changeset 52:a752c1af0670 tip

7902350: JCov 3.0,method mode: The instrumented OpenJDK 12 fails on starting with StackOverflowError Reviewed-by: shurailine Summary: Deprecated asm methods MethodInsnNode(int opcode, String owner, String name, String desc) replaced
author lkuskov
date Tue, 15 Jan 2019 14:35:58 -0800
parents a6cb513b3f94
children
files .hgignore src/classes/com/sun/tdk/jcov/JREInstr.java src/classes/com/sun/tdk/jcov/insert/AbstractUniversalInstrumenter.java src/classes/com/sun/tdk/jcov/instrument/ClassMorph.java src/classes/com/sun/tdk/jcov/instrument/DeferringMethodClassAdapter.java src/classes/com/sun/tdk/jcov/instrument/Instrumenter.java src/classes/com/sun/tdk/jcov/instrument/InvokeMethodAdapter.java src/classes/com/sun/tdk/jcov/instrument/StaticInvokeMethodAdapter.java src/classes/com/sun/tdk/jcov/util/Utils.java
diffstat 9 files changed, 71 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Tue Jan 15 14:35:58 2019 -0800
@@ -0,0 +1,17 @@
+syntax: glob
+
+# IDEA modules
+**.iml
+
+# build
+JCOV_BUILD/**
+
+# Misc
+webrev/**
+webrev.zip
+*~
+*.log
+*.swp
+
+# MAC OS
+*.DS_Store
--- a/src/classes/com/sun/tdk/jcov/JREInstr.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/JREInstr.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -177,7 +177,7 @@
                 logger.log(Level.SEVERE, "exception while creating mods, e = " + e);
             }
         } else if (toInstrument.getAbsolutePath().endsWith("bootmodules.jimage")) {
-            ArrayList<File> jdkImages = new ArrayList<File>();
+            ArrayList<File> jdkImages = new ArrayList<>();
             jdkImages.add(toInstrument);
             if (addJimages != null) {
                 Collections.addAll(jdkImages, addJimages);
@@ -243,9 +243,9 @@
 
         ArrayList<String> srcs = null;
         if (addJars != null) {
-            srcs = new ArrayList<String>();
-            for (int i = 0; i < addJars.length; ++i) {
-                srcs.add(addJars[i].getAbsolutePath());
+            srcs = new ArrayList<>();
+            for (File addJar : addJars) {
+                srcs.add(addJar.getAbsolutePath());
             }
         }
 
@@ -255,7 +255,7 @@
         }
 
         if (addTests != null) {
-            ArrayList<String> tests = new ArrayList<String>();
+            ArrayList<String> tests = new ArrayList<>();
             for (int i = 0; i < addTests.length; ++i) {
                 tests.add(addTests[i].getAbsolutePath());
             }
@@ -382,7 +382,7 @@
         return new File(jmodDir.getParentFile(), "instr_jimage_dir");
     }
 
-    private void createJMod(File jmodDir, File jdk, String rt_path) {
+        private void createJMod(File jmodDir, File jdk, String rt_path) {
         try {
             File modsDir = jmodDir.getParentFile();
             StringBuilder command = new StringBuilder();
@@ -403,8 +403,17 @@
                 if (subDir.getName().equals("conf")) {
                     command.append("--config " + jmodDir.getName() + File.separator + "conf ");
                 }
-                if (subDir.getName().equals("native")) {
-                    command.append("--libs " + jmodDir.getName() + File.separator + "native ");
+                if (subDir.getName().equals("lib")) {
+                    command.append("--libs " + jmodDir.getName() + File.separator + "lib ");
+                }
+                if (subDir.getName().equals("include")) {
+                    command.append("--header-files " + jmodDir.getName() + File.separator + "include ");
+                }
+                if (subDir.getName().equals("legal")) {
+                    command.append("--legal-notices " + jmodDir.getName() + File.separator + "legal ");
+                }
+                if (subDir.getName().equals("man")) {
+                    command.append("--man-pages " + jmodDir.getName() + File.separator + "man ");
                 }
             }
             command.append(" " + jmodDir.getName() + ".jmod");
@@ -675,7 +684,9 @@
                         }
                     } else {
                         if (!envHandler.isSet(Instr.DSC_SUBSEQUENT)) {
-                            throw new EnvHandlingException("Backup rt.jar.bak file exisit. It can mean that JRE is already instrumented - nothing to do. Restore initial rt.jar or delete bak file.");
+                            throw new EnvHandlingException("Backup rt.jar.bak file exists.\n" +
+                                    "It can mean that JRE is already instrumented - nothing to do.\n" +
+                                    "Restore initial rt.jar or delete bak file.");
                         }
                     }
 
@@ -717,7 +728,9 @@
                         }
                     } else {
                         if (!envHandler.isSet(Instr.DSC_SUBSEQUENT)) {
-                            throw new EnvHandlingException("Backup bootmodules.jimage.bak file exisit. It can mean that JRE is already instrumented - nothing to do. Restore initial bootmodules.jimage or delete bak file.");
+                            throw new EnvHandlingException("Backup bootmodules.jimage.bak file exists.\n" +
+                                    "It can mean that JRE is already instrumented - nothing to do.\n" +
+                                    "Restore initial bootmodules.jimage or delete bak file.");
                         }
                     }
                 }
@@ -816,4 +829,4 @@
             new OptionDescr("host", new String[]{"host"}, "sets default host", OptionDescr.VAL_SINGLE, "set the default host for sending jcov data. needed only in network mode");
     final static OptionDescr DSC_PORT =
             new OptionDescr("port", new String[]{"port"}, "sets default port", OptionDescr.VAL_SINGLE, "set the default port for sending jcov data. needed only in network mode");
-}
\ No newline at end of file
+}
--- a/src/classes/com/sun/tdk/jcov/insert/AbstractUniversalInstrumenter.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/insert/AbstractUniversalInstrumenter.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -101,8 +101,6 @@
     /**
      * <p> Creates AbstractUniversalInstrumenter instance </p>
      *
-     * @param outDir Directory to write output files to (jars, classes,
-     * resources)
      * @param overwrite Overwrite existing binary
      * @param readOnly Do not produce instrumented binaries (template generation
      * purposes)
--- a/src/classes/com/sun/tdk/jcov/instrument/ClassMorph.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/instrument/ClassMorph.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -203,7 +203,8 @@
 
             if (!params.isDynamicCollect() && !rtClassesInstrumented && isPreVMLoadClass(fullname)) {
                 rtClassesInstrumented = true;
-                logger.log(Level.WARNING, "It's possible that you are instrumenting classes which are loaded before VM is loaded. It's recomended to add saveatend at java/lang/Shutdown.runHooks method. Data could be lost otherwise.");
+                logger.log(Level.WARNING, "It's possible that you are instrumenting classes which are loaded before VM is loaded.\n" +
+                        "It's recomended to add saveatend at java/lang/Shutdown.runHooks method. Data could be lost otherwise.");
             }
 
             return res;
@@ -269,7 +270,8 @@
 
             if (!params.isDynamicCollect() && !rtClassesInstrumented && isPreVMLoadClass(fullname)) {
                 rtClassesInstrumented = true;
-                logger.log(Level.WARNING, "It's possible that you are instrumenting classes which are loaded before VM is loaded. It's recomended to add saveatend at java/lang/Shutdown.runHooks method. Data could be lost otherwise.");
+                logger.log(Level.WARNING, "It's possible that you are instrumenting classes which are loaded before VM is loaded.\n" +
+                        "It's recommended to add saveatend at java/lang/Shutdown.runHooks method. Data could be lost otherwise.");
             }
 
             return res;
--- a/src/classes/com/sun/tdk/jcov/instrument/DeferringMethodClassAdapter.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/instrument/DeferringMethodClassAdapter.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -173,7 +173,7 @@
         if ("<clinit>".equals(name) && !params.isDynamicCollect() && (k.getPackageName().startsWith("java/lang/"))) {
             mv = new MethodVisitor(Utils.ASM_API_VERSION, mv) {
                 public void visitCode() {
-                    mv.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/Collect", "init", "()V");
+                    mv.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/Collect", "init", "()V", false);
                     super.visitCode();
                 }
             };
@@ -186,15 +186,14 @@
             if (name.equals("<clinit>")) {
                 int id = (name + desc).hashCode();
                 mv.visitLdcInsn(id);
-                mv.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "setExpected", "(I)V");
+                mv.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "setExpected", "(I)V", false);
             }
 
         }
 
         if (params.isInnerInvacationsOff() && Utils.isAdvanceStaticInstrAllowed(k.getFullname(), name)) {
-
             if (name.equals("<clinit>")) {
-                mv.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "enterClinit", "()V");
+                mv.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "enterClinit", "()V", false);
             }
 
         }
--- a/src/classes/com/sun/tdk/jcov/instrument/Instrumenter.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/instrument/Instrumenter.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,15 +46,15 @@
             il.add(new LdcInsnNode(hash));
             il.add(new LdcInsnNode(fullHash));
             il.add(new MethodInsnNode(INVOKESTATIC,
-                    "com/sun/tdk/jcov/runtime/CollectDetect", "hit", "(III)V"));
+                    "com/sun/tdk/jcov/runtime/CollectDetect", "hit", "(III)V", false));
         } else if (detectInternal) { // agent (hardcoded by default) or loaded, false otherwise
             il.add(new LdcInsnNode(id));
             il.add(new MethodInsnNode(INVOKESTATIC,
-                    "com/sun/tdk/jcov/runtime/CollectDetect", "hit", "(I)V"));
+                    "com/sun/tdk/jcov/runtime/CollectDetect", "hit", "(I)V", false));
         } else { // static
             il.add(new LdcInsnNode(id));
             il.add(new MethodInsnNode(INVOKESTATIC,
-                    "com/sun/tdk/jcov/runtime/Collect", "hit", "(I)V"));
+                    "com/sun/tdk/jcov/runtime/Collect", "hit", "(I)V", false));
         }
         return il;
     }
--- a/src/classes/com/sun/tdk/jcov/instrument/InvokeMethodAdapter.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/instrument/InvokeMethodAdapter.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -83,7 +83,7 @@
                 && params.isCallerFilterAccept(className)) {
             InsnList il = new InsnList();
             il.add(new LdcInsnNode(getInvokeID(owner, name, desc)));
-            il.add(new MethodInsnNode(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "invokeHit", "(I)V"));
+            il.add(new MethodInsnNode(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "invokeHit", "(I)V", false));
             il.accept(this);
         }
         super.visitFieldInsn(opcode, owner, name, desc);
@@ -156,9 +156,9 @@
                 super.visitInsn(DUP);
 
                 super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/instrument/InvokeMethodAdapter",
-                        "getMethodHash", "(Ljava/lang/Object;)I");
+                        "getMethodHash", "(Ljava/lang/Object;)I", false);
                 super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect",
-                        "setExpectedFull", "(I)V");
+                        "setExpectedFull", "(I)V", false);
                 break;
             case METHOD:
                 super.visitInsn(DUP2_X1);
@@ -167,9 +167,9 @@
                 super.visitInsn(DUP);
 
                 super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/instrument/InvokeMethodAdapter",
-                        "getMethodHash", "(Ljava/lang/Object;)I");
+                        "getMethodHash", "(Ljava/lang/Object;)I", false);
                 super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect",
-                        "setExpectedFull", "(I)V");
+                        "setExpectedFull", "(I)V", false);
                 super.visitInsn(DUP_X2);
                 super.visitInsn(POP);
                 break;
@@ -178,9 +178,9 @@
                 super.visitInsn(POP);
 
                 super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/instrument/InvokeMethodAdapter",
-                        "getMethodHash", "(Ljava/lang/Object;)I");
+                        "getMethodHash", "(Ljava/lang/Object;)I", false);
                 super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect",
-                        "setExpectedFull", "(I)V");
+                        "setExpectedFull", "(I)V", false);
                 break;
             default:
                 break;
--- a/src/classes/com/sun/tdk/jcov/instrument/StaticInvokeMethodAdapter.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/instrument/StaticInvokeMethodAdapter.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -83,7 +83,7 @@
                 InsnList il = new InsnList();
                 il.add(new LdcInsnNode(id));
                 il.add(new MethodInsnNode(INVOKESTATIC,
-                        "com/sun/tdk/jcov/runtime/Collect", "hit", "(I)V"));
+                        "com/sun/tdk/jcov/runtime/Collect", "hit", "(I)V", false));
 
                 il.accept(this);
             }
@@ -141,9 +141,9 @@
                     if (!methName.equals("<clinit>")) {
                         int id = 0;
                         super.visitLdcInsn(id);
-                        super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "setExpected", "(I)V");
+                        super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "setExpected", "(I)V", false);
                     } else {
-                        super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "leaveClinit", "()V");
+                        super.visitMethodInsn(INVOKESTATIC, "com/sun/tdk/jcov/runtime/CollectDetect", "leaveClinit", "()V", false);
                     }
                 }
                 break;
--- a/src/classes/com/sun/tdk/jcov/util/Utils.java	Mon Nov 05 14:04:52 2018 -0800
+++ b/src/classes/com/sun/tdk/jcov/util/Utils.java	Tue Jan 15 14:35:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1344,7 +1344,6 @@
     }
 
     public static boolean isAdvanceStaticInstrAllowed(String classname, String methodname) {
-
         if ((!classname.equals("java/lang/System"))
                 && (!classname.equals("java/lang/String"))
                 && (!classname.equals("java/lang/StringLatin1"))
@@ -1357,8 +1356,6 @@
                 && (!classname.equals("java/lang/Class"))) {
             return true;
         }
-
-
         if (!methodname.equals("<clinit>")
                 && !methodname.equals("<init>")
                 && !methodname.equals("init")
@@ -1371,16 +1368,14 @@
                 && !methodname.equals("checkAccess")
                 && !methodname.equals("checkParentAccess")
                 && !methodname.equals("getSecurityManager")
+                && !methodname.equals("allowSecurityManager")
                 && !methodname.equals("registerNatives")
                 && !methodname.equals("currentTimeMillis")
                 && !methodname.equals("identityHashCode")
                 && !methodname.equals("nanoTime")
                 && !methodname.equals("getId")) {
-
             return true;
         }
-
-
         return false;
     }
-}
\ No newline at end of file
+}