# HG changeset patch # User amurillo # Date 1468598736 25200 # Node ID 8bc25e077e83ca9cee383771ddcb4f109ea696fb # Parent 4213518e20746fa0811e5438ac2f094c19ff0e7e# Parent d49ff02bacc9919d15c6bdc40e74328b217cf3ae Merge diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.base/share/native/include/jvmti.h --- a/jdk/src/java.base/share/native/include/jvmti.h Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.base/share/native/include/jvmti.h Fri Jul 15 09:05:36 2016 -0700 @@ -1217,8 +1217,11 @@ jmethodID method, jlocation location); - /* 40 : RESERVED */ - void *reserved40; + /* 40 : Get Named Module */ + jvmtiError (JNICALL *GetNamedModule) (jvmtiEnv* env, + jobject class_loader, + const char* package_name, + jobject* module_ptr); /* 41 : Set Field Access Watch */ jvmtiError (JNICALL *SetFieldAccessWatch) (jvmtiEnv* env, @@ -2146,6 +2149,12 @@ return functions->GetAllModules(this, module_count_ptr, modules_ptr); } + jvmtiError GetNamedModule(jobject class_loader, + const char* package_name, + jobject* module_ptr) { + return functions->GetNamedModule(this, class_loader, package_name, module_ptr); + } + jvmtiError GetLoadedClasses(jint* class_count_ptr, jclass** classes_ptr) { return functions->GetLoadedClasses(this, class_count_ptr, classes_ptr); diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java --- a/jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.instrument/share/classes/java/lang/instrument/ClassFileTransformer.java Fri Jul 15 09:05:36 2016 -0700 @@ -38,7 +38,7 @@ * A transformer of class files. An agent registers an implementation of this * interface using the {@link Instrumentation#addTransformer addTransformer} * method so that the transformer's {@link - * ClassFileTransformer#transform(Module,String,Class,ProtectionDomain,byte[]) + * ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[]) * transform} method is invoked when classes are loaded, * {@link Instrumentation#redefineClasses redefined}, or * {@link Instrumentation#retransformClasses retransformed}. The implementation @@ -170,13 +170,13 @@ /** * Transforms the given class file and returns a new replacement class file. * This method is invoked when the {@link Module Module} bearing {@link - * ClassFileTransformer#transform(Module,String,Class,ProtectionDomain,byte[]) + * ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[]) * transform} is not overridden. * * @implSpec The default implementation returns null. * * @param loader the defining loader of the class to be transformed, - * may be null if the bootstrap loader + * may be {@code null} if the bootstrap loader * @param className the name of the class in the internal form of fully * qualified class and interface names as defined in * The Java Virtual Machine Specification. @@ -208,9 +208,11 @@ * * @implSpec The default implementation of this method invokes the * {@link #transform(ClassLoader,String,Class,ProtectionDomain,byte[]) transform} - * method with the {@link Module#getClassLoader() ClassLoader} for the module. + * method. * * @param module the module of the class to be transformed + * @param loader the defining loader of the class to be transformed, + * may be {@code null} if the bootstrap loader * @param className the name of the class in the internal form of fully * qualified class and interface names as defined in * The Java Virtual Machine Specification. @@ -230,15 +232,13 @@ */ default byte[] transform( Module module, + ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { - PrivilegedAction pa = module::getClassLoader; - ClassLoader loader = AccessController.doPrivileged(pa); - // invoke the legacy transform method return transform(loader, className, diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java --- a/jdk/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.instrument/share/classes/java/lang/instrument/Instrumentation.java Fri Jul 15 09:05:36 2016 -0700 @@ -162,7 +162,7 @@ * *
  • for each transformer that was added with canRetransform * false, the bytes returned by - * {@link ClassFileTransformer#transform(Module,String,Class,ProtectionDomain,byte[]) + * {@link ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[]) * transform} during the last class load or redefine are * reused as the output of the transformation; note that this is * equivalent to reapplying the previous transformation, unaltered; @@ -170,7 +170,7 @@ *
  • *
  • for each transformer that was added with canRetransform * true, the - * {@link ClassFileTransformer#transform(Module,String,Class,ProtectionDomain,byte[]) + * {@link ClassFileTransformer#transform(Module,ClassLoader,String,Class,ProtectionDomain,byte[]) * transform} method is called in these transformers *
  • *
  • the transformed class file bytes are installed as the new diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java --- a/jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.instrument/share/classes/sun/instrument/InstrumentationImpl.java Fri Jul 15 09:05:36 2016 -0700 @@ -420,8 +420,8 @@ // WARNING: the native code knows the name & signature of this method private byte[] - transform( ClassLoader loader, - Module module, + transform( Module module, + ClassLoader loader, String classname, Class classBeingRedefined, ProtectionDomain protectionDomain, @@ -444,6 +444,7 @@ return null; // no manager, no transform } else { return mgr.transform( module, + loader, classname, classBeingRedefined, protectionDomain, diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.instrument/share/classes/sun/instrument/TransformerManager.java --- a/jdk/src/java.instrument/share/classes/sun/instrument/TransformerManager.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.instrument/share/classes/sun/instrument/TransformerManager.java Fri Jul 15 09:05:36 2016 -0700 @@ -169,6 +169,7 @@ public byte[] transform( Module module, + ClassLoader loader, String classname, Class classBeingRedefined, ProtectionDomain protectionDomain, @@ -187,6 +188,7 @@ try { transformedBytes = transformer.transform( module, + loader, classname, classBeingRedefined, protectionDomain, diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.c --- a/jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.c Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.c Fri Jul 15 09:05:36 2016 -0700 @@ -771,12 +771,11 @@ } static jobject -getModuleObject(JNIEnv * jnienv, +getModuleObject(jvmtiEnv* jvmti, jobject loaderObject, const char* cname) { - jboolean errorOutstanding = JNI_FALSE; + jvmtiError err = JVMTI_ERROR_NONE; jobject moduleObject = NULL; - jstring package = NULL; /* find last slash in the class name */ char* last_slash = (cname == NULL) ? NULL : strrchr(cname, '/'); @@ -789,14 +788,9 @@ } pkg_name_buf[len] = '\0'; - package = (*jnienv)->NewStringUTF(jnienv, pkg_name_buf); - jplis_assert_msg(package != NULL, "OOM error in NewStringUTF"); + err = (*jvmti)->GetNamedModule(jvmti, loaderObject, pkg_name_buf, &moduleObject); + jplis_assert_msg(err == JVMTI_ERROR_NONE, "error in the JVMTI GetNamedModule"); - moduleObject = JVM_GetModuleByPackageName(jnienv, loaderObject, package); - - errorOutstanding = checkForAndClearThrowable(jnienv); - jplis_assert_msg(!errorOutstanding, - "error in lookup of a module of the class being instrumented"); free((void*)pkg_name_buf); return moduleObject; } @@ -862,7 +856,7 @@ jobject moduleObject = NULL; if (classBeingRedefined == NULL) { - moduleObject = getModuleObject(jnienv, loaderObject, name); + moduleObject = getModuleObject(jvmti(agent), loaderObject, name); } else { // Redefine or retransform, InstrumentationImpl.transform() will use // classBeingRedefined.getModule() to get the module. @@ -873,8 +867,8 @@ jnienv, agent->mInstrumentationImpl, agent->mTransform, + moduleObject, loaderObject, - moduleObject, classNameStringObject, classBeingRedefined, protectionDomain, diff -r 4213518e2074 -r 8bc25e077e83 jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.h --- a/jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.h Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/src/java.instrument/share/native/libinstrument/JPLISAgent.h Fri Jul 15 09:05:36 2016 -0700 @@ -66,7 +66,7 @@ #define JPLIS_INSTRUMENTIMPL_AGENTMAININVOKER_METHODSIGNATURE "(Ljava/lang/String;Ljava/lang/String;)V" #define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODNAME "transform" #define JPLIS_INSTRUMENTIMPL_TRANSFORM_METHODSIGNATURE \ - "(Ljava/lang/ClassLoader;Ljava/lang/reflect/Module;Ljava/lang/String;Ljava/lang/Class;Ljava/security/ProtectionDomain;[BZ)[B" + "(Ljava/lang/reflect/Module;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/Class;Ljava/security/ProtectionDomain;[BZ)[B" /* diff -r 4213518e2074 -r 8bc25e077e83 jdk/test/ProblemList.txt --- a/jdk/test/ProblemList.txt Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/test/ProblemList.txt Fri Jul 15 09:05:36 2016 -0700 @@ -138,6 +138,8 @@ java/lang/instrument/BootClassPath/BootClassPathTest.sh 8072130 macosx-all +java/lang/instrument/DaemonThread/TestDaemonThread.java 8161225 generic-all + java/lang/management/MemoryMXBean/LowMemoryTest.java 8130339 generic-all java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all diff -r 4213518e2074 -r 8bc25e077e83 jdk/test/java/lang/instrument/ATransformerManagementTestCase.java --- a/jdk/test/java/lang/instrument/ATransformerManagementTestCase.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/test/java/lang/instrument/ATransformerManagementTestCase.java Fri Jul 15 09:05:36 2016 -0700 @@ -302,6 +302,7 @@ public byte[] transform( Module module, + ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, @@ -311,6 +312,7 @@ if (classBeingRedefined != null) checkInTransformer(MyClassFileTransformer.this); return super.transform( module, + loader, className, classBeingRedefined, protectionDomain, diff -r 4213518e2074 -r 8bc25e077e83 jdk/test/java/lang/instrument/RetransformAgent.java --- a/jdk/test/java/lang/instrument/RetransformAgent.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/test/java/lang/instrument/RetransformAgent.java Fri Jul 15 09:05:36 2016 -0700 @@ -69,6 +69,7 @@ } public byte[] transform(Module module, + ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, diff -r 4213518e2074 -r 8bc25e077e83 jdk/test/java/lang/instrument/SimpleIdentityTransformer.java --- a/jdk/test/java/lang/instrument/SimpleIdentityTransformer.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/test/java/lang/instrument/SimpleIdentityTransformer.java Fri Jul 15 09:05:36 2016 -0700 @@ -63,6 +63,7 @@ public byte[] transform( Module module, + ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, diff -r 4213518e2074 -r 8bc25e077e83 jdk/test/sun/tools/jps/JpsBase.java --- a/jdk/test/sun/tools/jps/JpsBase.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/test/sun/tools/jps/JpsBase.java Fri Jul 15 09:05:36 2016 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, 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 @@ -59,7 +59,17 @@ return JpsBase.class.getName(); } + private static boolean userDirSanityCheck(String fullProcessName) { + String userDir = System.getProperty("user.dir"); + if (!fullProcessName.startsWith(userDir)) { + System.err.printf("Test skipped. user.dir '%s' is not a prefix of '%s'\n", userDir, fullProcessName); + return false; + } + return true; + } + public static void main(String[] args) throws Exception { + System.out.printf("INFO: user.dir: '%s''\n", System.getProperty("user.dir")); long pid = ProcessTools.getProcessId(); List> combinations = JpsHelper.JpsArg.generateCombinations(); @@ -85,8 +95,12 @@ // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ... isFull = true; String fullProcessName = getFullProcessName(); - pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*"; - output.shouldMatch(pattern); + // Skip the test if user.dir is not a prefix of the current path + // It's possible if the test is run from symlinked dir or windows alias drive + if (userDirSanityCheck(fullProcessName)) { + pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*"; + output.shouldMatch(pattern); + } break; case m: // If '-m' is specified output should contain the arguments passed to the main method: diff -r 4213518e2074 -r 8bc25e077e83 jdk/test/sun/tools/jps/TestJpsJar.java --- a/jdk/test/sun/tools/jps/TestJpsJar.java Thu Jul 14 19:42:16 2016 -0700 +++ b/jdk/test/sun/tools/jps/TestJpsJar.java Fri Jul 15 09:05:36 2016 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2016, 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 @@ -52,6 +52,7 @@ cmd.addAll(JpsHelper.getVmArgs()); cmd.add("-Dtest.jdk=" + testJdk); cmd.add("-Dtest.src=" + testSrc); + cmd.add("-Duser.dir=" + System.getProperty("user.dir")); cmd.add("-jar"); cmd.add(jar.getAbsolutePath()); cmd.add("monkey");