This commit is contained in:
Alejandro Murillo 2016-07-15 09:05:36 -07:00
commit 2bff7015a6
13 changed files with 57 additions and 30 deletions

@ -1217,8 +1217,11 @@ typedef struct jvmtiInterface_1_ {
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 @@ struct _jvmtiEnv {
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);

@ -38,7 +38,7 @@ import java.security.ProtectionDomain;
* 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 @@ public interface ClassFileTransformer {
/**
* 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 <code>null</code> 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
* <i>The Java Virtual Machine Specification</i>.
@ -208,9 +208,11 @@ public interface ClassFileTransformer {
*
* @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
* <i>The Java Virtual Machine Specification</i>.
@ -230,15 +232,13 @@ public interface ClassFileTransformer {
*/
default byte[]
transform( Module module,
ClassLoader loader,
String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer)
throws IllegalClassFormatException {
PrivilegedAction<ClassLoader> pa = module::getClassLoader;
ClassLoader loader = AccessController.doPrivileged(pa);
// invoke the legacy transform method
return transform(loader,
className,

@ -162,7 +162,7 @@ public interface Instrumentation {
* </li>
* <li>for each transformer that was added with <code>canRetransform</code>
* 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 @@ public interface Instrumentation {
* </li>
* <li>for each transformer that was added with <code>canRetransform</code>
* 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
* </li>
* <li>the transformed class file bytes are installed as the new

@ -420,8 +420,8 @@ public class InstrumentationImpl implements Instrumentation {
// 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 @@ public class InstrumentationImpl implements Instrumentation {
return null; // no manager, no transform
} else {
return mgr.transform( module,
loader,
classname,
classBeingRedefined,
protectionDomain,

@ -169,6 +169,7 @@ public class TransformerManager
public byte[]
transform( Module module,
ClassLoader loader,
String classname,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
@ -187,6 +188,7 @@ public class TransformerManager
try {
transformedBytes = transformer.transform( module,
loader,
classname,
classBeingRedefined,
protectionDomain,

@ -771,12 +771,11 @@ addRedefineClassesCapability(JPLISAgent * agent) {
}
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 @@ getModuleObject(JNIEnv * jnienv,
}
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 @@ transformClassFile( JPLISAgent * agent,
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 @@ transformClassFile( JPLISAgent * agent,
jnienv,
agent->mInstrumentationImpl,
agent->mTransform,
loaderObject,
moduleObject,
loaderObject,
classNameStringObject,
classBeingRedefined,
protectionDomain,

@ -66,7 +66,7 @@ typedef struct _JPLISEnvironment JPLISEnvironment;
#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"
/*

@ -138,6 +138,8 @@ java/lang/instrument/RetransformBigClass.sh 8061177 generic-
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

@ -302,6 +302,7 @@ ATransformerManagementTestCase
public byte[]
transform(
Module module,
ClassLoader loader,
String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
@ -311,6 +312,7 @@ ATransformerManagementTestCase
if (classBeingRedefined != null) checkInTransformer(MyClassFileTransformer.this);
return super.transform( module,
loader,
className,
classBeingRedefined,
protectionDomain,

@ -69,6 +69,7 @@ class RetransformAgent {
}
public byte[] transform(Module module,
ClassLoader loader,
String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,

@ -63,6 +63,7 @@ SimpleIdentityTransformer implements ClassFileTransformer {
public byte[]
transform(
Module module,
ClassLoader loader,
String className,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,

@ -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 @@ public final class JpsBase {
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<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
@ -85,8 +95,12 @@ public final class JpsBase {
// 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:

@ -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 @@ public class TestJpsJar {
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");