Merge
This commit is contained in:
commit
be69c9cfa3
@ -636,7 +636,11 @@ public interface Instrumentation {
|
|||||||
* @param transformer
|
* @param transformer
|
||||||
* The ClassFileTransformer which wraps using this prefix.
|
* The ClassFileTransformer which wraps using this prefix.
|
||||||
* @param prefix
|
* @param prefix
|
||||||
* The prefix which has been applied to wrapped native methods.
|
* The prefix to apply to wrapped native methods when
|
||||||
|
* retrying a failed native method resolution. If prefix
|
||||||
|
* is either <code>null</code> or the empty string, then
|
||||||
|
* failed native method resolutions are not retried for
|
||||||
|
* this transformer.
|
||||||
* @throws java.lang.NullPointerException if passed a <code>null</code> transformer.
|
* @throws java.lang.NullPointerException if passed a <code>null</code> transformer.
|
||||||
* @throws java.lang.UnsupportedOperationException if the current configuration of
|
* @throws java.lang.UnsupportedOperationException if the current configuration of
|
||||||
* the JVM does not allow setting a native method prefix
|
* the JVM does not allow setting a native method prefix
|
||||||
|
@ -303,39 +303,78 @@ public class InstrumentationImpl implements Instrumentation {
|
|||||||
NoSuchMethodException firstExc = null;
|
NoSuchMethodException firstExc = null;
|
||||||
boolean twoArgAgent = false;
|
boolean twoArgAgent = false;
|
||||||
|
|
||||||
// The agent class has a premain or agentmain method that has 1 or 2
|
// The agent class must have a premain or agentmain method that
|
||||||
// arguments. We first check for a signature of (String, Instrumentation),
|
// has 1 or 2 arguments. We check in the following order:
|
||||||
// and if not found we check for (String). If neither is found then we
|
//
|
||||||
// throw the NoSuchMethodException from the first attempt so that the
|
// 1) declared with a signature of (String, Instrumentation)
|
||||||
// exception text indicates the lookup failed for the 2-arg method
|
// 2) declared with a signature of (String)
|
||||||
// (same as JDK5.0).
|
// 3) inherited with a signature of (String, Instrumentation)
|
||||||
|
// 4) inherited with a signature of (String)
|
||||||
|
//
|
||||||
|
// So the declared version of either 1-arg or 2-arg always takes
|
||||||
|
// primary precedence over an inherited version. After that, the
|
||||||
|
// 2-arg version takes precedence over the 1-arg version.
|
||||||
|
//
|
||||||
|
// If no method is found then we throw the NoSuchMethodException
|
||||||
|
// from the first attempt so that the exception text indicates
|
||||||
|
// the lookup failed for the 2-arg method (same as JDK5.0).
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m = javaAgentClass.getMethod( methodname,
|
m = javaAgentClass.getDeclaredMethod( methodname,
|
||||||
new Class[] {
|
new Class[] {
|
||||||
String.class,
|
String.class,
|
||||||
java.lang.instrument.Instrumentation.class
|
java.lang.instrument.Instrumentation.class
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
twoArgAgent = true;
|
twoArgAgent = true;
|
||||||
} catch (NoSuchMethodException x) {
|
} catch (NoSuchMethodException x) {
|
||||||
// remember the NoSuchMethodException
|
// remember the NoSuchMethodException
|
||||||
firstExc = x;
|
firstExc = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for the 1-arg method
|
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
|
// now try the declared 1-arg method
|
||||||
try {
|
try {
|
||||||
m = javaAgentClass.getMethod(methodname, new Class[] { String.class });
|
m = javaAgentClass.getDeclaredMethod(methodname,
|
||||||
|
new Class[] { String.class });
|
||||||
} catch (NoSuchMethodException x) {
|
} catch (NoSuchMethodException x) {
|
||||||
// Neither method exists so we throw the first NoSuchMethodException
|
// ignore this exception because we'll try
|
||||||
// as per 5.0
|
// two arg inheritance next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m == null) {
|
||||||
|
// now try the inherited 2-arg method
|
||||||
|
try {
|
||||||
|
m = javaAgentClass.getMethod( methodname,
|
||||||
|
new Class[] {
|
||||||
|
String.class,
|
||||||
|
java.lang.instrument.Instrumentation.class
|
||||||
|
}
|
||||||
|
);
|
||||||
|
twoArgAgent = true;
|
||||||
|
} catch (NoSuchMethodException x) {
|
||||||
|
// ignore this exception because we'll try
|
||||||
|
// one arg inheritance next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m == null) {
|
||||||
|
// finally try the inherited 1-arg method
|
||||||
|
try {
|
||||||
|
m = javaAgentClass.getMethod(methodname,
|
||||||
|
new Class[] { String.class });
|
||||||
|
} catch (NoSuchMethodException x) {
|
||||||
|
// none of the methods exists so we throw the
|
||||||
|
// first NoSuchMethodException as per 5.0
|
||||||
throw firstExc;
|
throw firstExc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the premain method should not be required to be public,
|
// the premain method should not be required to be public,
|
||||||
// make it accessible so we can call it
|
// make it accessible so we can call it
|
||||||
|
// Note: The spec says the following:
|
||||||
|
// The agent class must implement a public static premain method...
|
||||||
setAccessible(m, true);
|
setAccessible(m, true);
|
||||||
|
|
||||||
// invoke the 1 or 2-arg method
|
// invoke the 1 or 2-arg method
|
||||||
|
@ -626,6 +626,7 @@ appendClassPath( JPLISAgent* agent,
|
|||||||
jvmtiError jvmtierr;
|
jvmtiError jvmtierr;
|
||||||
|
|
||||||
jvmtierr = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, jarfile);
|
jvmtierr = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, jarfile);
|
||||||
|
check_phase_ret_1(jvmtierr);
|
||||||
|
|
||||||
if (jvmtierr == JVMTI_ERROR_NONE) {
|
if (jvmtierr == JVMTI_ERROR_NONE) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -634,6 +635,7 @@ appendClassPath( JPLISAgent* agent,
|
|||||||
jvmtiError err;
|
jvmtiError err;
|
||||||
|
|
||||||
err = (*jvmtienv)->GetPhase(jvmtienv, &phase);
|
err = (*jvmtienv)->GetPhase(jvmtienv, &phase);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(err == JVMTI_ERROR_NONE);
|
jplis_assert(err == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
if (phase == JVMTI_PHASE_LIVE) {
|
if (phase == JVMTI_PHASE_LIVE) {
|
||||||
@ -805,6 +807,8 @@ appendBootClassPath( JPLISAgent* agent,
|
|||||||
|
|
||||||
/* print warning if boot class path not updated */
|
/* print warning if boot class path not updated */
|
||||||
if (jvmtierr != JVMTI_ERROR_NONE) {
|
if (jvmtierr != JVMTI_ERROR_NONE) {
|
||||||
|
check_phase_blob_ret(jvmtierr, free(path));
|
||||||
|
|
||||||
fprintf(stderr, "WARNING: %s not added to bootstrap class loader search: ", path);
|
fprintf(stderr, "WARNING: %s not added to bootstrap class loader search: ", path);
|
||||||
switch (jvmtierr) {
|
switch (jvmtierr) {
|
||||||
case JVMTI_ERROR_ILLEGAL_ARGUMENT :
|
case JVMTI_ERROR_ILLEGAL_ARGUMENT :
|
||||||
|
@ -179,6 +179,7 @@ getJPLISEnvironment(jvmtiEnv * jvmtienv) {
|
|||||||
jvmtierror = (*jvmtienv)->GetEnvironmentLocalStorage(
|
jvmtierror = (*jvmtienv)->GetEnvironmentLocalStorage(
|
||||||
jvmtienv,
|
jvmtienv,
|
||||||
(void**)&environment);
|
(void**)&environment);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
if (jvmtierror == JVMTI_ERROR_NONE) {
|
if (jvmtierror == JVMTI_ERROR_NONE) {
|
||||||
@ -230,6 +231,7 @@ createNewJPLISAgent(JavaVM * vm, JPLISAgent **agent_ptr) {
|
|||||||
/* don't leak envs */
|
/* don't leak envs */
|
||||||
if ( initerror != JPLIS_INIT_ERROR_NONE ) {
|
if ( initerror != JPLIS_INIT_ERROR_NONE ) {
|
||||||
jvmtiError jvmtierror = (*jvmtienv)->DisposeEnvironment(jvmtienv);
|
jvmtiError jvmtierror = (*jvmtienv)->DisposeEnvironment(jvmtienv);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +261,7 @@ initializeJPLISAgent( JPLISAgent * agent,
|
|||||||
agent->mNormalEnvironment.mIsRetransformer = JNI_FALSE;
|
agent->mNormalEnvironment.mIsRetransformer = JNI_FALSE;
|
||||||
agent->mRetransformEnvironment.mJVMTIEnv = NULL; /* NULL until needed */
|
agent->mRetransformEnvironment.mJVMTIEnv = NULL; /* NULL until needed */
|
||||||
agent->mRetransformEnvironment.mAgent = agent;
|
agent->mRetransformEnvironment.mAgent = agent;
|
||||||
agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE;
|
agent->mRetransformEnvironment.mIsRetransformer = JNI_FALSE; /* JNI_FALSE until mJVMTIEnv is set */
|
||||||
agent->mAgentmainCaller = NULL;
|
agent->mAgentmainCaller = NULL;
|
||||||
agent->mInstrumentationImpl = NULL;
|
agent->mInstrumentationImpl = NULL;
|
||||||
agent->mPremainCaller = NULL;
|
agent->mPremainCaller = NULL;
|
||||||
@ -277,18 +279,25 @@ initializeJPLISAgent( JPLISAgent * agent,
|
|||||||
jvmtierror = (*jvmtienv)->SetEnvironmentLocalStorage(
|
jvmtierror = (*jvmtienv)->SetEnvironmentLocalStorage(
|
||||||
jvmtienv,
|
jvmtienv,
|
||||||
&(agent->mNormalEnvironment));
|
&(agent->mNormalEnvironment));
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
/* check what capabilities are available */
|
/* check what capabilities are available */
|
||||||
checkCapabilities(agent);
|
checkCapabilities(agent);
|
||||||
|
|
||||||
/* check phase - if live phase then we don't need the VMInit event */
|
/* check phase - if live phase then we don't need the VMInit event */
|
||||||
jvmtierror == (*jvmtienv)->GetPhase(jvmtienv, &phase);
|
jvmtierror = (*jvmtienv)->GetPhase(jvmtienv, &phase);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
if (phase == JVMTI_PHASE_LIVE) {
|
if (phase == JVMTI_PHASE_LIVE) {
|
||||||
return JPLIS_INIT_ERROR_NONE;
|
return JPLIS_INIT_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (phase != JVMTI_PHASE_ONLOAD) {
|
||||||
|
/* called too early or called too late; either way bail out */
|
||||||
|
return JPLIS_INIT_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* now turn on the VMInit event */
|
/* now turn on the VMInit event */
|
||||||
if ( jvmtierror == JVMTI_ERROR_NONE ) {
|
if ( jvmtierror == JVMTI_ERROR_NONE ) {
|
||||||
jvmtiEventCallbacks callbacks;
|
jvmtiEventCallbacks callbacks;
|
||||||
@ -298,6 +307,7 @@ initializeJPLISAgent( JPLISAgent * agent,
|
|||||||
jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
|
jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
|
||||||
&callbacks,
|
&callbacks,
|
||||||
sizeof(callbacks));
|
sizeof(callbacks));
|
||||||
|
check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,6 +317,7 @@ initializeJPLISAgent( JPLISAgent * agent,
|
|||||||
JVMTI_ENABLE,
|
JVMTI_ENABLE,
|
||||||
JVMTI_EVENT_VM_INIT,
|
JVMTI_EVENT_VM_INIT,
|
||||||
NULL /* all threads */);
|
NULL /* all threads */);
|
||||||
|
check_phase_ret_blob(jvmtierror, JPLIS_INIT_ERROR_FAILURE);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,6 +633,7 @@ setLivePhaseEventHandlers( JPLISAgent * agent) {
|
|||||||
jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
|
jvmtierror = (*jvmtienv)->SetEventCallbacks( jvmtienv,
|
||||||
&callbacks,
|
&callbacks,
|
||||||
sizeof(callbacks));
|
sizeof(callbacks));
|
||||||
|
check_phase_ret_false(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
|
|
||||||
@ -632,6 +644,7 @@ setLivePhaseEventHandlers( JPLISAgent * agent) {
|
|||||||
JVMTI_DISABLE,
|
JVMTI_DISABLE,
|
||||||
JVMTI_EVENT_VM_INIT,
|
JVMTI_EVENT_VM_INIT,
|
||||||
NULL /* all threads */);
|
NULL /* all threads */);
|
||||||
|
check_phase_ret_false(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,6 +655,7 @@ setLivePhaseEventHandlers( JPLISAgent * agent) {
|
|||||||
JVMTI_ENABLE,
|
JVMTI_ENABLE,
|
||||||
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
|
JVMTI_EVENT_CLASS_FILE_LOAD_HOOK,
|
||||||
NULL /* all threads */);
|
NULL /* all threads */);
|
||||||
|
check_phase_ret_false(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -660,6 +674,7 @@ checkCapabilities(JPLISAgent * agent) {
|
|||||||
memset(&potentialCapabilities, 0, sizeof(potentialCapabilities));
|
memset(&potentialCapabilities, 0, sizeof(potentialCapabilities));
|
||||||
|
|
||||||
jvmtierror = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &potentialCapabilities);
|
jvmtierror = (*jvmtienv)->GetPotentialCapabilities(jvmtienv, &potentialCapabilities);
|
||||||
|
check_phase_ret(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
if ( jvmtierror == JVMTI_ERROR_NONE ) {
|
if ( jvmtierror == JVMTI_ERROR_NONE ) {
|
||||||
@ -681,9 +696,11 @@ enableNativeMethodPrefixCapability(jvmtiEnv * jvmtienv) {
|
|||||||
jvmtiError jvmtierror;
|
jvmtiError jvmtierror;
|
||||||
|
|
||||||
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
|
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
desiredCapabilities.can_set_native_method_prefix = 1;
|
desiredCapabilities.can_set_native_method_prefix = 1;
|
||||||
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
|
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
|
||||||
|
check_phase_ret(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,9 +732,11 @@ addOriginalMethodOrderCapability(JPLISAgent * agent) {
|
|||||||
jvmtiError jvmtierror;
|
jvmtiError jvmtierror;
|
||||||
|
|
||||||
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
|
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
desiredCapabilities.can_maintain_original_method_order = 1;
|
desiredCapabilities.can_maintain_original_method_order = 1;
|
||||||
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
|
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
|
||||||
|
check_phase_ret(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,9 +751,11 @@ addRedefineClassesCapability(JPLISAgent * agent) {
|
|||||||
|
|
||||||
if (agent->mRedefineAvailable && !agent->mRedefineAdded) {
|
if (agent->mRedefineAvailable && !agent->mRedefineAdded) {
|
||||||
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
|
jvmtierror = (*jvmtienv)->GetCapabilities(jvmtienv, &desiredCapabilities);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
desiredCapabilities.can_redefine_classes = 1;
|
desiredCapabilities.can_redefine_classes = 1;
|
||||||
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
|
jvmtierror = (*jvmtienv)->AddCapabilities(jvmtienv, &desiredCapabilities);
|
||||||
|
check_phase_ret(jvmtierror);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* With mixed premain/agentmain agents then it's possible that the
|
* With mixed premain/agentmain agents then it's possible that the
|
||||||
@ -998,6 +1019,7 @@ retransformableEnvironment(JPLISAgent * agent) {
|
|||||||
if (jvmtierror == JVMTI_ERROR_NONE) {
|
if (jvmtierror == JVMTI_ERROR_NONE) {
|
||||||
// install the retransforming environment
|
// install the retransforming environment
|
||||||
agent->mRetransformEnvironment.mJVMTIEnv = retransformerEnv;
|
agent->mRetransformEnvironment.mJVMTIEnv = retransformerEnv;
|
||||||
|
agent->mRetransformEnvironment.mIsRetransformer = JNI_TRUE;
|
||||||
|
|
||||||
// Make it for ClassFileLoadHook handling
|
// Make it for ClassFileLoadHook handling
|
||||||
jvmtierror = (*retransformerEnv)->SetEnvironmentLocalStorage(
|
jvmtierror = (*retransformerEnv)->SetEnvironmentLocalStorage(
|
||||||
@ -1025,6 +1047,7 @@ isModifiableClass(JNIEnv * jnienv, JPLISAgent * agent, jclass clazz) {
|
|||||||
jvmtierror = (*jvmtienv)->IsModifiableClass( jvmtienv,
|
jvmtierror = (*jvmtienv)->IsModifiableClass( jvmtienv,
|
||||||
clazz,
|
clazz,
|
||||||
&is_modifiable);
|
&is_modifiable);
|
||||||
|
check_phase_ret_false(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
return is_modifiable;
|
return is_modifiable;
|
||||||
@ -1032,7 +1055,7 @@ isModifiableClass(JNIEnv * jnienv, JPLISAgent * agent, jclass clazz) {
|
|||||||
|
|
||||||
jboolean
|
jboolean
|
||||||
isRetransformClassesSupported(JNIEnv * jnienv, JPLISAgent * agent) {
|
isRetransformClassesSupported(JNIEnv * jnienv, JPLISAgent * agent) {
|
||||||
return retransformableEnvironment(agent) != NULL;
|
return agent->mRetransformEnvironment.mIsRetransformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1075,6 +1098,12 @@ retransformClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classes) {
|
|||||||
numClasses = (*jnienv)->GetArrayLength(jnienv, classes);
|
numClasses = (*jnienv)->GetArrayLength(jnienv, classes);
|
||||||
errorOccurred = checkForThrowable(jnienv);
|
errorOccurred = checkForThrowable(jnienv);
|
||||||
jplis_assert(!errorOccurred);
|
jplis_assert(!errorOccurred);
|
||||||
|
|
||||||
|
if (!errorOccurred && numClasses == 0) {
|
||||||
|
jplis_assert(numClasses != 0);
|
||||||
|
errorOccurred = JNI_TRUE;
|
||||||
|
errorCode = JVMTI_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!errorOccurred) {
|
if (!errorOccurred) {
|
||||||
@ -1096,6 +1125,13 @@ retransformClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classes) {
|
|||||||
if (errorOccurred) {
|
if (errorOccurred) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (classArray[index] == NULL) {
|
||||||
|
jplis_assert(classArray[index] != NULL);
|
||||||
|
errorOccurred = JNI_TRUE;
|
||||||
|
errorCode = JVMTI_ERROR_NULL_POINTER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1217,6 +1253,7 @@ redefineClasses(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray classDefinitio
|
|||||||
if (!errorOccurred) {
|
if (!errorOccurred) {
|
||||||
jvmtiError errorCode = JVMTI_ERROR_NONE;
|
jvmtiError errorCode = JVMTI_ERROR_NONE;
|
||||||
errorCode = (*jvmtienv)->RedefineClasses(jvmtienv, numDefs, classDefs);
|
errorCode = (*jvmtienv)->RedefineClasses(jvmtienv, numDefs, classDefs);
|
||||||
|
check_phase_blob_ret(errorCode, deallocate(jvmtienv, (void*)classDefs));
|
||||||
errorOccurred = (errorCode != JVMTI_ERROR_NONE);
|
errorOccurred = (errorCode != JVMTI_ERROR_NONE);
|
||||||
if ( errorOccurred ) {
|
if ( errorOccurred ) {
|
||||||
createAndThrowThrowableFromJVMTIErrorCode(jnienv, errorCode);
|
createAndThrowThrowableFromJVMTIErrorCode(jnienv, errorCode);
|
||||||
@ -1250,6 +1287,7 @@ commonGetClassList( JNIEnv * jnienv,
|
|||||||
classLoader,
|
classLoader,
|
||||||
&classCount,
|
&classCount,
|
||||||
&classes);
|
&classes);
|
||||||
|
check_phase_ret_blob(jvmtierror, localArray);
|
||||||
errorOccurred = (jvmtierror != JVMTI_ERROR_NONE);
|
errorOccurred = (jvmtierror != JVMTI_ERROR_NONE);
|
||||||
jplis_assert(!errorOccurred);
|
jplis_assert(!errorOccurred);
|
||||||
|
|
||||||
@ -1311,6 +1349,7 @@ getObjectSize(JNIEnv * jnienv, JPLISAgent * agent, jobject objectToSize) {
|
|||||||
jvmtiError jvmtierror = JVMTI_ERROR_NONE;
|
jvmtiError jvmtierror = JVMTI_ERROR_NONE;
|
||||||
|
|
||||||
jvmtierror = (*jvmtienv)->GetObjectSize(jvmtienv, objectToSize, &objectSize);
|
jvmtierror = (*jvmtienv)->GetObjectSize(jvmtienv, objectToSize, &objectSize);
|
||||||
|
check_phase_ret_0(jvmtierror);
|
||||||
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
jplis_assert(jvmtierror == JVMTI_ERROR_NONE);
|
||||||
if ( jvmtierror != JVMTI_ERROR_NONE ) {
|
if ( jvmtierror != JVMTI_ERROR_NONE ) {
|
||||||
createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
|
createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
|
||||||
@ -1360,6 +1399,7 @@ appendToClassLoaderSearch(JNIEnv * jnienv, JPLISAgent * agent, jstring jarFile,
|
|||||||
} else {
|
} else {
|
||||||
jvmtierror = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, platformChars);
|
jvmtierror = (*jvmtienv)->AddToSystemClassLoaderSearch(jvmtienv, platformChars);
|
||||||
}
|
}
|
||||||
|
check_phase_ret(jvmtierror);
|
||||||
|
|
||||||
if ( jvmtierror != JVMTI_ERROR_NONE ) {
|
if ( jvmtierror != JVMTI_ERROR_NONE ) {
|
||||||
createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
|
createAndThrowThrowableFromJVMTIErrorCode(jnienv, jvmtierror);
|
||||||
@ -1450,6 +1490,7 @@ setNativeMethodPrefixes(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray prefix
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = (*jvmtienv)->SetNativeMethodPrefixes(jvmtienv, inx, (char**)prefixes);
|
err = (*jvmtienv)->SetNativeMethodPrefixes(jvmtienv, inx, (char**)prefixes);
|
||||||
|
/* can be called from any phase */
|
||||||
jplis_assert(err == JVMTI_ERROR_NONE);
|
jplis_assert(err == JVMTI_ERROR_NONE);
|
||||||
|
|
||||||
for (i = 0; i < inx; i++) {
|
for (i = 0; i < inx; i++) {
|
||||||
|
@ -266,6 +266,48 @@ setNativeMethodPrefixes(JNIEnv * jnienv, JPLISAgent * agent, jobjectArray prefix
|
|||||||
|
|
||||||
#define jvmti(a) a->mNormalEnvironment.mJVMTIEnv
|
#define jvmti(a) a->mNormalEnvironment.mJVMTIEnv
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A set of macros for insulating the JLI method callers from
|
||||||
|
* JVMTI_ERROR_WRONG_PHASE return codes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* for a JLI method where "blob" is executed before simply returning */
|
||||||
|
#define check_phase_blob_ret(ret, blob) \
|
||||||
|
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
|
||||||
|
blob; \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for a JLI method where simply returning is benign */
|
||||||
|
#define check_phase_ret(ret) \
|
||||||
|
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for a JLI method where returning zero (0) is benign */
|
||||||
|
#define check_phase_ret_0(ret) \
|
||||||
|
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
|
||||||
|
return 0; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for a JLI method where returning one (1) is benign */
|
||||||
|
#define check_phase_ret_1(ret) \
|
||||||
|
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
|
||||||
|
return 1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for a case where a specific "blob" must be returned */
|
||||||
|
#define check_phase_ret_blob(ret, blob) \
|
||||||
|
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
|
||||||
|
return (blob); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for a JLI method where returning false is benign */
|
||||||
|
#define check_phase_ret_false(ret) \
|
||||||
|
if ((ret) == JVMTI_ERROR_WRONG_PHASE) { \
|
||||||
|
return (jboolean) 0; \
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
@ -23,6 +23,14 @@
|
|||||||
* have any questions.
|
* have any questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
/*
|
||||||
|
* Win* needs this include. However, Linux and Solaris do not.
|
||||||
|
* Having this include on Solaris SPARC breaks having non US-ASCII
|
||||||
|
* characters in the value of the Premain-Class attribute.
|
||||||
|
*/
|
||||||
|
#include <ctype.h>
|
||||||
|
#endif /* _WIN32 */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -45,11 +53,37 @@ doAttribute(const char* name, const char* value, void* user_data) {
|
|||||||
if (attribute->name == NULL) {
|
if (attribute->name == NULL) {
|
||||||
free(attribute);
|
free(attribute);
|
||||||
} else {
|
} else {
|
||||||
attribute->value = strdup(value);
|
char *begin = (char *)value;
|
||||||
|
char *end;
|
||||||
|
size_t value_len;
|
||||||
|
|
||||||
|
/* skip any leading white space */
|
||||||
|
while (isspace(*begin)) {
|
||||||
|
begin++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* skip any trailing white space */
|
||||||
|
end = &begin[strlen(begin)];
|
||||||
|
while (end > begin && isspace(end[-1])) {
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (begin == end) {
|
||||||
|
/* no value so skip this attribute */
|
||||||
|
free(attribute->name);
|
||||||
|
free(attribute);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
value_len = (size_t)(end - begin);
|
||||||
|
attribute->value = malloc(value_len + 1);
|
||||||
if (attribute->value == NULL) {
|
if (attribute->value == NULL) {
|
||||||
free(attribute->name);
|
free(attribute->name);
|
||||||
free(attribute);
|
free(attribute);
|
||||||
} else {
|
} else {
|
||||||
|
/* save the value without leading or trailing whitespace */
|
||||||
|
strncpy(attribute->value, begin, value_len);
|
||||||
|
attribute->value[value_len] = '\0';
|
||||||
attribute->next = NULL;
|
attribute->next = NULL;
|
||||||
if (context->head == NULL) {
|
if (context->head == NULL) {
|
||||||
context->head = attribute;
|
context->head = attribute;
|
||||||
|
@ -74,6 +74,7 @@ confirmingTLSSet( jvmtiEnv * jvmtienv,
|
|||||||
jvmtienv,
|
jvmtienv,
|
||||||
thread,
|
thread,
|
||||||
newValue);
|
newValue);
|
||||||
|
check_phase_ret_blob(error, error);
|
||||||
|
|
||||||
#if JPLISASSERT_ENABLEASSERTIONS
|
#if JPLISASSERT_ENABLEASSERTIONS
|
||||||
assertTLSValue( jvmtienv,
|
assertTLSValue( jvmtienv,
|
||||||
@ -96,6 +97,7 @@ assertTLSValue( jvmtiEnv * jvmtienv,
|
|||||||
jvmtienv,
|
jvmtienv,
|
||||||
thread,
|
thread,
|
||||||
&test);
|
&test);
|
||||||
|
check_phase_ret(error);
|
||||||
jplis_assert(error == JVMTI_ERROR_NONE);
|
jplis_assert(error == JVMTI_ERROR_NONE);
|
||||||
jplis_assert(test == expected);
|
jplis_assert(test == expected);
|
||||||
}
|
}
|
||||||
@ -111,6 +113,7 @@ tryToAcquireReentrancyToken( jvmtiEnv * jvmtienv,
|
|||||||
jvmtienv,
|
jvmtienv,
|
||||||
thread,
|
thread,
|
||||||
&storedValue);
|
&storedValue);
|
||||||
|
check_phase_ret_false(error);
|
||||||
jplis_assert(error == JVMTI_ERROR_NONE);
|
jplis_assert(error == JVMTI_ERROR_NONE);
|
||||||
if ( error == JVMTI_ERROR_NONE ) {
|
if ( error == JVMTI_ERROR_NONE ) {
|
||||||
/* if this thread is already inside, just return false and short-circuit */
|
/* if this thread is already inside, just return false and short-circuit */
|
||||||
|
@ -46,6 +46,7 @@ allocate(jvmtiEnv * jvmtienv, size_t bytecount) {
|
|||||||
error = (*jvmtienv)->Allocate(jvmtienv,
|
error = (*jvmtienv)->Allocate(jvmtienv,
|
||||||
bytecount,
|
bytecount,
|
||||||
(unsigned char**) &resultBuffer);
|
(unsigned char**) &resultBuffer);
|
||||||
|
/* may be called from any phase */
|
||||||
jplis_assert(error == JVMTI_ERROR_NONE);
|
jplis_assert(error == JVMTI_ERROR_NONE);
|
||||||
if ( error != JVMTI_ERROR_NONE ) {
|
if ( error != JVMTI_ERROR_NONE ) {
|
||||||
resultBuffer = NULL;
|
resultBuffer = NULL;
|
||||||
@ -66,6 +67,7 @@ deallocate(jvmtiEnv * jvmtienv, void * buffer) {
|
|||||||
|
|
||||||
error = (*jvmtienv)->Deallocate(jvmtienv,
|
error = (*jvmtienv)->Deallocate(jvmtienv,
|
||||||
(unsigned char*)buffer);
|
(unsigned char*)buffer);
|
||||||
|
/* may be called from any phase */
|
||||||
jplis_assert_msg(error == JVMTI_ERROR_NONE, "Can't deallocate memory");
|
jplis_assert_msg(error == JVMTI_ERROR_NONE, "Can't deallocate memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,10 @@
|
|||||||
|
|
||||||
# @test
|
# @test
|
||||||
# @bug 5055293
|
# @bug 5055293
|
||||||
# @summary Test non US-ASCII characters in the value of the Boot-Class-Path
|
# @summary Test non US-ASCII characters in the value of the Boot-Class-Path
|
||||||
# attribute.
|
# attribute.
|
||||||
|
#
|
||||||
|
# @run shell/timeout=240 BootClassPathTest.sh
|
||||||
|
|
||||||
if [ "${TESTJAVA}" = "" ]
|
if [ "${TESTJAVA}" = "" ]
|
||||||
then
|
then
|
||||||
@ -72,7 +74,7 @@ echo "Creating agent jar file..."
|
|||||||
|
|
||||||
echo "Running test..."
|
echo "Running test..."
|
||||||
|
|
||||||
"${JAVA}" -javaagent:"${TESTCLASSES}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
|
"${JAVA}" ${TESTVMOPTS} -javaagent:"${TESTCLASSES}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
|
||||||
result=$?
|
result=$?
|
||||||
|
|
||||||
echo "Cleanup..."
|
echo "Cleanup..."
|
||||||
|
@ -70,9 +70,11 @@ JAR="${TESTJAVA}/bin/jar"
|
|||||||
cp ${TESTSRC}/${AGENT}.java .
|
cp ${TESTSRC}/${AGENT}.java .
|
||||||
cp ${TESTSRC}/${APP}.java .
|
cp ${TESTSRC}/${APP}.java .
|
||||||
rm -rf ilib
|
rm -rf ilib
|
||||||
cp -r ${TESTSRC}/ilib .
|
mkdir ilib
|
||||||
mkdir bootpath
|
cp ${TESTSRC}/ilib/*.java ilib
|
||||||
cp -r ${TESTSRC}/bootreporter bootpath
|
rm -rf bootpath
|
||||||
|
mkdir -p bootpath/bootreporter
|
||||||
|
cp ${TESTSRC}/bootreporter/*.java bootpath/bootreporter
|
||||||
|
|
||||||
cd bootpath
|
cd bootpath
|
||||||
${JAVAC} bootreporter/*.java
|
${JAVAC} bootreporter/*.java
|
||||||
|
483
jdk/test/java/lang/instrument/ManifestTest.sh
Normal file
483
jdk/test/java/lang/instrument/ManifestTest.sh
Normal file
@ -0,0 +1,483 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 6274276
|
||||||
|
# @summary JLI JAR manifest processing should ignore leading and trailing white space.
|
||||||
|
# @author Daniel D. Daugherty
|
||||||
|
#
|
||||||
|
# @run build ManifestTestApp
|
||||||
|
# @run shell/timeout=900 ManifestTest.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
make_a_JAR() {
|
||||||
|
# version_line and premain_line are required
|
||||||
|
version_line="Manifest-Version: 1.0"
|
||||||
|
premain_line="Premain-Class: ${AGENT}"
|
||||||
|
boot_cp_line=""
|
||||||
|
expect_boot_cp_line="ExampleForBootClassPath was not loaded."
|
||||||
|
can_redef_line=""
|
||||||
|
expect_redef_line="isRedefineClassesSupported()=false"
|
||||||
|
can_retrans_line=""
|
||||||
|
expect_retrans_line="isRetransformClassesSupported()=false"
|
||||||
|
can_set_nmp_line=""
|
||||||
|
expect_set_nmp_line="isNativeMethodPrefixSupported()=false"
|
||||||
|
|
||||||
|
while [ $# != 0 ] ; do
|
||||||
|
case "$1" in
|
||||||
|
defaults)
|
||||||
|
# just use the defaults for the test
|
||||||
|
;;
|
||||||
|
|
||||||
|
boot_cp_line1)
|
||||||
|
boot_cp_line="Boot-Class-Path: no_white_space"
|
||||||
|
expect_boot_cp_line="ExampleForBootClassPath was loaded."
|
||||||
|
mkdir -p no_white_space
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class no_white_space
|
||||||
|
;;
|
||||||
|
|
||||||
|
boot_cp_line2)
|
||||||
|
boot_cp_line="Boot-Class-Path: has_leading_blank"
|
||||||
|
expect_boot_cp_line="ExampleForBootClassPath was loaded."
|
||||||
|
mkdir -p has_leading_blank " has_leading_blank"
|
||||||
|
# the good class is in the directory without the blank
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
|
||||||
|
has_leading_blank
|
||||||
|
# the bad class is in the directory with the blank
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
|
||||||
|
" has_leading_blank"/ExampleForBootClassPath.class
|
||||||
|
;;
|
||||||
|
|
||||||
|
boot_cp_line3)
|
||||||
|
boot_cp_line="Boot-Class-Path: has_trailing_blank "
|
||||||
|
expect_boot_cp_line="ExampleForBootClassPath was loaded."
|
||||||
|
mkdir -p has_trailing_blank "has_trailing_blank "
|
||||||
|
# the good class is in the directory without the blank
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
|
||||||
|
has_trailing_blank
|
||||||
|
# the bad class is in the directory with the blank
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
|
||||||
|
"has_trailing_blank "/ExampleForBootClassPath.class
|
||||||
|
;;
|
||||||
|
|
||||||
|
boot_cp_line4)
|
||||||
|
boot_cp_line="Boot-Class-Path: has_leading_and_trailing_blank "
|
||||||
|
expect_boot_cp_line="ExampleForBootClassPath was loaded."
|
||||||
|
mkdir -p has_leading_and_trailing_blank \
|
||||||
|
" has_leading_and_trailing_blank "
|
||||||
|
# the good class is in the directory without the blanks
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class \
|
||||||
|
has_leading_and_trailing_blank
|
||||||
|
# the bad class is in the directory with the blanks
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
|
||||||
|
" has_leading_and_trailing_blank "/ExampleForBootClassPath.class
|
||||||
|
;;
|
||||||
|
|
||||||
|
boot_cp_line5)
|
||||||
|
boot_cp_line="Boot-Class-Path: has_embedded blank"
|
||||||
|
expect_boot_cp_line="ExampleForBootClassPath was loaded."
|
||||||
|
mkdir -p has_embedded "has_embedded blank"
|
||||||
|
# the good class is in the first blank separated word
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class has_embedded
|
||||||
|
# the bad class is in the directory with the blank
|
||||||
|
cp -p $OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad \
|
||||||
|
"has_embedded blank"/ExampleForBootClassPath.class
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line1)
|
||||||
|
can_redef_line="Can-Redefine-Classes: true"
|
||||||
|
expect_redef_line="isRedefineClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line2)
|
||||||
|
can_redef_line="Can-Redefine-Classes: true"
|
||||||
|
expect_redef_line="isRedefineClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line3)
|
||||||
|
can_redef_line="Can-Redefine-Classes: true "
|
||||||
|
expect_redef_line="isRedefineClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line4)
|
||||||
|
can_redef_line="Can-Redefine-Classes: true "
|
||||||
|
expect_redef_line="isRedefineClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line5)
|
||||||
|
can_redef_line="Can-Redefine-Classes: false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line6)
|
||||||
|
can_redef_line="Can-Redefine-Classes: false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line7)
|
||||||
|
can_redef_line="Can-Redefine-Classes: false "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line8)
|
||||||
|
can_redef_line="Can-Redefine-Classes: false "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line9)
|
||||||
|
# this line makes the jar command unhappy and that's
|
||||||
|
# not what we're testing so skip this case
|
||||||
|
can_redef_line="Can-Redefine-Classes:"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line10)
|
||||||
|
can_redef_line="Can-Redefine-Classes: "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_redef_line11)
|
||||||
|
can_redef_line="Can-Redefine-Classes: "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line1)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: true"
|
||||||
|
expect_retrans_line="isRetransformClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line2)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: true"
|
||||||
|
expect_retrans_line="isRetransformClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line3)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: true "
|
||||||
|
expect_retrans_line="isRetransformClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line4)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: true "
|
||||||
|
expect_retrans_line="isRetransformClassesSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line5)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line6)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line7)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: false "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line8)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: false "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line9)
|
||||||
|
# this line makes the jar command unhappy and that's
|
||||||
|
# not what we're testing so skip this case
|
||||||
|
can_retrans_line="Can-Retransform-Classes:"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line10)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_retrans_line11)
|
||||||
|
can_retrans_line="Can-Retransform-Classes: "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line1)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: true"
|
||||||
|
expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line2)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: true"
|
||||||
|
expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line3)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: true "
|
||||||
|
expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line4)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: true "
|
||||||
|
expect_set_nmp_line="isNativeMethodPrefixSupported()=true"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line5)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line6)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: false"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line7)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: false "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line8)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: false "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line9)
|
||||||
|
# this line makes the jar command unhappy and that's
|
||||||
|
# not what we're testing so skip this case
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix:"
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line10)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: "
|
||||||
|
;;
|
||||||
|
|
||||||
|
can_set_nmp_line11)
|
||||||
|
can_set_nmp_line="Can-Set-Native-Method-Prefix: "
|
||||||
|
;;
|
||||||
|
|
||||||
|
premain_line1)
|
||||||
|
premain_line="Premain-Class: ${AGENT}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
premain_line2)
|
||||||
|
premain_line="Premain-Class: ${AGENT} "
|
||||||
|
;;
|
||||||
|
|
||||||
|
premain_line3)
|
||||||
|
premain_line="Premain-Class: ${AGENT} "
|
||||||
|
;;
|
||||||
|
|
||||||
|
version_line1)
|
||||||
|
version_line="Manifest-Version: 1.0"
|
||||||
|
;;
|
||||||
|
|
||||||
|
version_line2)
|
||||||
|
version_line="Manifest-Version: 1.0 "
|
||||||
|
;;
|
||||||
|
|
||||||
|
version_line3)
|
||||||
|
version_line="Manifest-Version: 1.0 "
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
echo "ERROR: invalid test token"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "${version_line}" > ${AGENT}.mf
|
||||||
|
echo "${premain_line}" >> ${AGENT}.mf
|
||||||
|
|
||||||
|
if [ -n "$boot_cp_line" ]; then
|
||||||
|
echo "${boot_cp_line}" >> ${AGENT}.mf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$can_redef_line" ]; then
|
||||||
|
echo "${can_redef_line}" >> ${AGENT}.mf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$can_retrans_line" ]; then
|
||||||
|
echo "${can_retrans_line}" >> ${AGENT}.mf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$can_set_nmp_line" ]; then
|
||||||
|
echo "${can_set_nmp_line}" >> ${AGENT}.mf
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f ${AGENT}.jar
|
||||||
|
${JAR} cvfm ${AGENT}.jar ${AGENT}.mf ${AGENT}.class
|
||||||
|
|
||||||
|
echo "$expect_boot_cp_line" > expect_boot_cp_line
|
||||||
|
echo "$expect_redef_line" > expect_redef_line
|
||||||
|
echo "$expect_retrans_line" > expect_retrans_line
|
||||||
|
echo "$expect_set_nmp_line" > expect_set_nmp_line
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAR="${TESTJAVA}/bin/jar"
|
||||||
|
JAVAC="${TESTJAVA}"/bin/javac
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
# Now that ManifestTestApp.class is built, we move
|
||||||
|
# ExampleForBootClassPath.class so that it cannot be found
|
||||||
|
# by default
|
||||||
|
OUT_OF_THE_WAY=out_of_the_way
|
||||||
|
mkdir $OUT_OF_THE_WAY
|
||||||
|
mv "${TESTCLASSES}/ExampleForBootClassPath.class" $OUT_OF_THE_WAY
|
||||||
|
|
||||||
|
# create a bad version of ExampleForBootClassPath.class
|
||||||
|
# so we can tell when the wrong version is run
|
||||||
|
sed 's/return 15/return 42/' "${TESTSRC}"/ExampleForBootClassPath.java \
|
||||||
|
> ExampleForBootClassPath.java
|
||||||
|
"$JAVAC" ExampleForBootClassPath.java
|
||||||
|
mv ExampleForBootClassPath.class \
|
||||||
|
$OUT_OF_THE_WAY/ExampleForBootClassPath.class.bad
|
||||||
|
mv ExampleForBootClassPath.java \
|
||||||
|
$OUT_OF_THE_WAY/ExampleForBootClassPath.java.bad
|
||||||
|
|
||||||
|
AGENT=ManifestTestAgent
|
||||||
|
# We compile the agent in the working directory instead of with
|
||||||
|
# a build task because we construct a different agent JAR file
|
||||||
|
# for each test case.
|
||||||
|
${JAVAC} -d . ${TESTSRC}/${AGENT}.java
|
||||||
|
|
||||||
|
FAIL_MARKER=fail_marker
|
||||||
|
rm -f $FAIL_MARKER
|
||||||
|
|
||||||
|
while read token; do
|
||||||
|
echo
|
||||||
|
echo "===== begin test case: $token ====="
|
||||||
|
make_a_JAR "$token"
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} -javaagent:${AGENT}.jar \
|
||||||
|
-classpath "${TESTCLASSES}" ManifestTestApp > output.log 2>&1
|
||||||
|
result=$?
|
||||||
|
|
||||||
|
cat output.log
|
||||||
|
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: ManifestTestApp exited with status of 0."
|
||||||
|
else
|
||||||
|
echo "FAIL: ManifestTestApp exited with status of $result"
|
||||||
|
touch $FAIL_MARKER
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESG="Hello from ${AGENT}!"
|
||||||
|
grep -s "$MESG" output.log > /dev/null
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
touch $FAIL_MARKER
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESG=`cat expect_boot_cp_line`
|
||||||
|
grep -s "$MESG" output.log > /dev/null
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
touch $FAIL_MARKER
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESG=`cat expect_redef_line`
|
||||||
|
grep -s "$MESG" output.log > /dev/null
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
touch $FAIL_MARKER
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESG=`cat expect_retrans_line`
|
||||||
|
grep -s "$MESG" output.log > /dev/null
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
touch $FAIL_MARKER
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESG=`cat expect_set_nmp_line`
|
||||||
|
grep -s "$MESG" output.log > /dev/null
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
touch $FAIL_MARKER
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "===== end test case: $token ====="
|
||||||
|
echo
|
||||||
|
done << EOF
|
||||||
|
defaults
|
||||||
|
version_line1
|
||||||
|
version_line2
|
||||||
|
version_line3
|
||||||
|
premain_line1
|
||||||
|
premain_line2
|
||||||
|
premain_line3
|
||||||
|
boot_cp_line1
|
||||||
|
boot_cp_line2
|
||||||
|
boot_cp_line3
|
||||||
|
boot_cp_line4
|
||||||
|
boot_cp_line5
|
||||||
|
can_redef_line1
|
||||||
|
can_redef_line2
|
||||||
|
can_redef_line3
|
||||||
|
can_redef_line4
|
||||||
|
can_redef_line5
|
||||||
|
can_redef_line6
|
||||||
|
can_redef_line7
|
||||||
|
can_redef_line8
|
||||||
|
can_redef_line10
|
||||||
|
can_redef_line11
|
||||||
|
can_retrans_line1
|
||||||
|
can_retrans_line2
|
||||||
|
can_retrans_line3
|
||||||
|
can_retrans_line4
|
||||||
|
can_retrans_line5
|
||||||
|
can_retrans_line6
|
||||||
|
can_retrans_line7
|
||||||
|
can_retrans_line8
|
||||||
|
can_retrans_line10
|
||||||
|
can_retrans_line11
|
||||||
|
can_set_nmp_line1
|
||||||
|
can_set_nmp_line2
|
||||||
|
can_set_nmp_line3
|
||||||
|
can_set_nmp_line4
|
||||||
|
can_set_nmp_line5
|
||||||
|
can_set_nmp_line6
|
||||||
|
can_set_nmp_line7
|
||||||
|
can_set_nmp_line8
|
||||||
|
can_set_nmp_line10
|
||||||
|
can_set_nmp_line11
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ -f $FAIL_MARKER ]; then
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
41
jdk/test/java/lang/instrument/ManifestTestAgent.java
Normal file
41
jdk/test/java/lang/instrument/ManifestTestAgent.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
|
||||||
|
public class ManifestTestAgent {
|
||||||
|
private static Instrumentation instrumentation;
|
||||||
|
|
||||||
|
private ManifestTestAgent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void premain(String agentArgs, Instrumentation inst) {
|
||||||
|
System.out.println("Hello from ManifestTestAgent!");
|
||||||
|
System.out.println("isNativeMethodPrefixSupported()=" +
|
||||||
|
inst.isNativeMethodPrefixSupported());
|
||||||
|
System.out.println("isRedefineClassesSupported()=" +
|
||||||
|
inst.isRedefineClassesSupported());
|
||||||
|
System.out.println("isRetransformClassesSupported()=" +
|
||||||
|
inst.isRetransformClassesSupported());
|
||||||
|
}
|
||||||
|
}
|
69
jdk/test/java/lang/instrument/ManifestTestApp.java
Normal file
69
jdk/test/java/lang/instrument/ManifestTestApp.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ManifestTestApp {
|
||||||
|
public static void main(String args[]) {
|
||||||
|
System.out.println("Hello from ManifestTestApp!");
|
||||||
|
|
||||||
|
new ManifestTestApp().doTest();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTest() {
|
||||||
|
try {
|
||||||
|
// load the class only found via the Boot-Class-Path attribute
|
||||||
|
Object instance = loadExampleClass();
|
||||||
|
if (instance.getClass().getClassLoader() == null) {
|
||||||
|
System.out.println("PASS: ExampleForBootClassPath was loaded" +
|
||||||
|
" by the boot class path loader.");
|
||||||
|
} else {
|
||||||
|
System.out.println("FAIL: ExampleForBootClassPath was loaded" +
|
||||||
|
" by a non-boot class path loader.");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
} catch (NoClassDefFoundError ncdfe) {
|
||||||
|
// This message just lets ManifestTest.sh know whether or
|
||||||
|
// not ExampleForBootClassPath was loaded. Depending on
|
||||||
|
// the current test case, that will be either a PASSing
|
||||||
|
// condition or a FAILing condition as determined by
|
||||||
|
// ManifestTest.sh.
|
||||||
|
System.out.println("ExampleForBootClassPath was not loaded.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object loadExampleClass() {
|
||||||
|
ExampleForBootClassPath instance = new ExampleForBootClassPath();
|
||||||
|
System.out.println("ExampleForBootClassPath was loaded.");
|
||||||
|
if (instance.fifteen() == 15) {
|
||||||
|
System.out.println("PASS: the correct" +
|
||||||
|
" ExampleForBootClassPath was loaded.");
|
||||||
|
} else {
|
||||||
|
System.out.println("FAIL: the wrong ExampleForBootClassPath" +
|
||||||
|
" was loaded.");
|
||||||
|
System.out.println("FAIL: instance.fifteen()=" +
|
||||||
|
instance.fifteen());
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@
|
|||||||
* @summary test setNativeMethodPrefix
|
* @summary test setNativeMethodPrefix
|
||||||
* @author Robert Field, Sun Microsystems
|
* @author Robert Field, Sun Microsystems
|
||||||
*
|
*
|
||||||
* @run shell MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
|
* @run shell/timeout=240 MakeJAR2.sh NativeMethodPrefixAgent NativeMethodPrefixApp 'Can-Retransform-Classes: true' 'Can-Set-Native-Method-Prefix: true'
|
||||||
* @run main/othervm -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp
|
* @run main/othervm -javaagent:NativeMethodPrefixAgent.jar NativeMethodPrefixApp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
72
jdk/test/java/lang/instrument/ParallelTransformerLoader.sh
Normal file
72
jdk/test/java/lang/instrument/ParallelTransformerLoader.sh
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 5088398
|
||||||
|
# @summary Test parallel class loading by parallel transformers.
|
||||||
|
# @author Daniel D. Daugherty as modified from the code of Daryl Puryear @ Wily
|
||||||
|
#
|
||||||
|
# @run shell MakeJAR3.sh ParallelTransformerLoaderAgent
|
||||||
|
# @run build ParallelTransformerLoaderApp
|
||||||
|
# @run shell/timeout=240 ParallelTransformerLoader.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAR="${TESTJAVA}"/bin/jar
|
||||||
|
JAVAC="${TESTJAVA}"/bin/javac
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
"${JAVAC}" -d . \
|
||||||
|
"${TESTSRC}"/TestClass1.java \
|
||||||
|
"${TESTSRC}"/TestClass2.java \
|
||||||
|
"${TESTSRC}"/TestClass3.java
|
||||||
|
|
||||||
|
"${JAR}" cvf Test.jar Test*.class
|
||||||
|
# Removing the test class files is important. If these
|
||||||
|
# .class files are available on the classpath other
|
||||||
|
# than via Test.jar, then the deadlock will not reproduce.
|
||||||
|
rm -f Test*.class
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} -javaagent:ParallelTransformerLoaderAgent.jar=Test.jar \
|
||||||
|
-classpath "${TESTCLASSES}" ParallelTransformerLoaderApp
|
||||||
|
result=$?
|
||||||
|
echo "result=$result"
|
||||||
|
|
||||||
|
exit $result
|
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
import java.net.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.security.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Java Agent
|
||||||
|
*
|
||||||
|
* @author Daryl Puryear
|
||||||
|
* @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
public class ParallelTransformerLoaderAgent
|
||||||
|
{
|
||||||
|
private static URL sURL;
|
||||||
|
private static ClassLoader sClassLoader;
|
||||||
|
|
||||||
|
public static synchronized ClassLoader
|
||||||
|
getClassLoader()
|
||||||
|
{
|
||||||
|
return sClassLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void
|
||||||
|
generateNewClassLoader()
|
||||||
|
{
|
||||||
|
sClassLoader = new URLClassLoader(new URL[] {sURL});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void
|
||||||
|
premain( String agentArgs,
|
||||||
|
Instrumentation instrumentation)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
if (agentArgs == null || agentArgs == "")
|
||||||
|
{
|
||||||
|
System.err.println("Error: No jar file name provided, test will not run.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sURL = (new File(agentArgs)).toURL();
|
||||||
|
System.out.println("Using jar file: " + sURL);
|
||||||
|
generateNewClassLoader();
|
||||||
|
|
||||||
|
instrumentation.addTransformer(new TestTransformer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestTransformer
|
||||||
|
implements ClassFileTransformer
|
||||||
|
{
|
||||||
|
public byte[]
|
||||||
|
transform( ClassLoader loader,
|
||||||
|
String className,
|
||||||
|
Class classBeingRedefined,
|
||||||
|
ProtectionDomain protectionDomain,
|
||||||
|
byte[] classfileBuffer)
|
||||||
|
throws IllegalClassFormatException
|
||||||
|
{
|
||||||
|
String tName = Thread.currentThread().getName();
|
||||||
|
// In 160_03 and older, transform() is called
|
||||||
|
// with the "system_loader_lock" held and that
|
||||||
|
// prevents the bootstrap class loaded from
|
||||||
|
// running in parallel. If we add a slight sleep
|
||||||
|
// delay here when the transform() call is not
|
||||||
|
// main or TestThread, then the deadlock in
|
||||||
|
// 160_03 and older is much more reproducible.
|
||||||
|
if (!tName.equals("main") && !tName.equals("TestThread")) {
|
||||||
|
System.out.println("Thread '" + tName +
|
||||||
|
"' has called transform()");
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// load additional classes when called from other threads
|
||||||
|
if (!tName.equals("main"))
|
||||||
|
{
|
||||||
|
loadClasses(3);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void
|
||||||
|
loadClasses( int index)
|
||||||
|
{
|
||||||
|
ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("TestClass" + index, true, loader);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Java Program
|
||||||
|
*
|
||||||
|
* @author Daryl Puryear
|
||||||
|
* @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
public class ParallelTransformerLoaderApp
|
||||||
|
{
|
||||||
|
private static final int kNumIterations = 1000;
|
||||||
|
|
||||||
|
public static void
|
||||||
|
main( String[] args)
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
System.out.println();
|
||||||
|
System.out.print("Starting test with " + kNumIterations + " iterations");
|
||||||
|
for (int i = 0; i < kNumIterations; i++)
|
||||||
|
{
|
||||||
|
// load some classes from multiple threads (this thread and one other)
|
||||||
|
Thread testThread = new TestThread(2);
|
||||||
|
testThread.start();
|
||||||
|
loadClasses(1);
|
||||||
|
|
||||||
|
// log that it completed and reset for the next iteration
|
||||||
|
testThread.join();
|
||||||
|
System.out.print(".");
|
||||||
|
ParallelTransformerLoaderAgent.generateNewClassLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("Test completed successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TestThread
|
||||||
|
extends Thread
|
||||||
|
{
|
||||||
|
private final int fIndex;
|
||||||
|
|
||||||
|
public
|
||||||
|
TestThread( int index)
|
||||||
|
{
|
||||||
|
super("TestThread");
|
||||||
|
|
||||||
|
fIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void
|
||||||
|
run()
|
||||||
|
{
|
||||||
|
loadClasses(fIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void
|
||||||
|
loadClasses( int index)
|
||||||
|
{
|
||||||
|
ClassLoader loader = ParallelTransformerLoaderAgent.getClassLoader();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("TestClass" + index, true, loader);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,11 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
* dummy "Hello World"ish application for "premain" tests
|
||||||
*
|
|
||||||
* Used by PremainClassTest.sh - dummy "main application" which doesn't do anything
|
|
||||||
*/
|
*/
|
||||||
public class DummyMain {
|
public class DummyMain {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello from DummyMain!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,0,0,1): declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0001
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0001.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0001 extends InheritAgent0001Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0001!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0001Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,0,1,0): declared 2-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0010
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0010.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0010 extends InheritAgent0010Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent0010!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0010Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,0,1,1): declared 2-arg and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0011
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0011.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0011 extends InheritAgent0011Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0011!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent0011!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0011Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,1,0,0): inherited 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0100
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0100.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0100 extends InheritAgent0100Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0100Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0100Super!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,1,0,1): inherited 1-arg and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0101
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0101.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0101 extends InheritAgent0101Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0101!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0101Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0101Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,1,1,0): inherited 1-arg and declared 2-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0110
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0110.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0110 extends InheritAgent0110Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a one argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent0110!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0110Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0110Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (0,1,1,1): inherited 1-arg, declared 2-arg and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent0111
|
||||||
|
* @run main/othervm -javaagent:InheritAgent0111.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent0111 extends InheritAgent0111Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0111!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent0111!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent0111Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent0111Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,0,0,0): inherited 2-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1000
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1000.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1000 extends InheritAgent1000Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1000Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1000Super!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,0,0,1): inherited 2-arg, and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1001
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1001.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1001 extends InheritAgent1001Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1001!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1001Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1001Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,0,1,0): inherited 2-arg, and declared 2-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1010
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1010.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1010 extends InheritAgent1010Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1010!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1010Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1010Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,0,1,1): inherited 2-arg, declared 2-arg and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1011
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1011.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1011 extends InheritAgent1011Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1011!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1011!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1011Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1011Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,1,0,0): inherited 2-arg and inherited 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1100
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1100.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1100 extends InheritAgent1100Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1100Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1100Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1100Super!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,1,0,1): inherited 2-arg, inherited 1-arg, and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1101
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1101.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1101 extends InheritAgent1101Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1101!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This agent does NOT have a double argument premain() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1101Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1101Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1101Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,1,1,0): inherited 2-arg, inherited 1-arg, and declared 2-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1110
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1110.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1110 extends InheritAgent1110Super {
|
||||||
|
|
||||||
|
// This agent does NOT have a single argument premain() method.
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1110!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1110Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1110Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1110Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 6289149
|
||||||
|
* @summary test config (1,1,1,1): inherited 2-arg, inherited 1-arg, declared 2-arg and declared 1-arg in agent class
|
||||||
|
* @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
*
|
||||||
|
* @run shell ../MakeJAR3.sh InheritAgent1111
|
||||||
|
* @run main/othervm -javaagent:InheritAgent1111.jar DummyMain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class InheritAgent1111 extends InheritAgent1111Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1111!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1111!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InheritAgent1111Super {
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a single argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs) {
|
||||||
|
System.out.println("Hello from Single-Arg InheritAgent1111Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// This agent has a double argument premain() method which
|
||||||
|
// is NOT the one that should be called.
|
||||||
|
//
|
||||||
|
public static void premain (String agentArgs, Instrumentation instArg) {
|
||||||
|
System.out.println("Hello from Double-Arg InheritAgent1111Super!");
|
||||||
|
throw new Error("ERROR: THIS AGENT SHOULD NOT HAVE BEEN CALLED.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class NoPremainAgent {
|
||||||
|
|
||||||
|
// This agent is missing the premain() function.
|
||||||
|
}
|
68
jdk/test/java/lang/instrument/PremainClass/NoPremainAgent.sh
Normal file
68
jdk/test/java/lang/instrument/PremainClass/NoPremainAgent.sh
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 6289149
|
||||||
|
# @summary test when the agent's class is missing the premain() function.
|
||||||
|
# @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
#
|
||||||
|
# @run build DummyMain
|
||||||
|
# @run shell ../MakeJAR3.sh NoPremainAgent
|
||||||
|
# @run shell NoPremainAgent.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAVAC="${TESTJAVA}"/bin/javac
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} -javaagent:NoPremainAgent.jar \
|
||||||
|
-classpath "${TESTCLASSES}" DummyMain > output.log 2>&1
|
||||||
|
cat output.log
|
||||||
|
|
||||||
|
MESG="java.lang.NoSuchMethodException"
|
||||||
|
grep "$MESG" output.log
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $result
|
@ -49,7 +49,7 @@ JAVA="${TESTJAVA}"/bin/java
|
|||||||
|
|
||||||
"$JAVAC" -d "${TESTCLASSES}" "${TESTSRC}"/DummyMain.java
|
"$JAVAC" -d "${TESTCLASSES}" "${TESTSRC}"/DummyMain.java
|
||||||
|
|
||||||
"${JAVA}" -javaagent:"${TESTSRC}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
|
"${JAVA}" ${TESTVMOPTS} -javaagent:"${TESTSRC}"/Agent.jar -classpath "${TESTCLASSES}" DummyMain
|
||||||
result=$?
|
result=$?
|
||||||
|
|
||||||
exit $result
|
exit $result
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
class ZeroArgPremainAgent {
|
||||||
|
|
||||||
|
// This agent has a zero arg premain() function.
|
||||||
|
public static void premain () {
|
||||||
|
System.out.println("Hello from ZeroArgInheritAgent!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 6289149
|
||||||
|
# @summary test when the agent's class has a zero arg premain() function.
|
||||||
|
# @author Daniel D. Daugherty, Sun Microsystems
|
||||||
|
#
|
||||||
|
# @run build DummyMain
|
||||||
|
# @run shell ../MakeJAR3.sh ZeroArgPremainAgent
|
||||||
|
# @run shell ZeroArgPremainAgent.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAVAC="${TESTJAVA}"/bin/javac
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} -javaagent:ZeroArgPremainAgent.jar \
|
||||||
|
-classpath "${TESTCLASSES}" DummyMain > output.log 2>&1
|
||||||
|
cat output.log
|
||||||
|
|
||||||
|
MESG="java.lang.NoSuchMethodException"
|
||||||
|
grep "$MESG" output.log
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: found '$MESG' in the test output"
|
||||||
|
else
|
||||||
|
echo "FAIL: did NOT find '$MESG' in the test output"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $result
|
@ -0,0 +1,81 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 5003341 4917140 6545149
|
||||||
|
# @summary Redefine a class with a native method.
|
||||||
|
# @author Daniel D. Daugherty as modified from the test submitted by clovis@par.univie.ac.at
|
||||||
|
#
|
||||||
|
# @run shell MakeJAR3.sh RedefineClassWithNativeMethodAgent 'Can-Redefine-Classes: true'
|
||||||
|
# @run build RedefineClassWithNativeMethodApp
|
||||||
|
# @run shell RedefineClassWithNativeMethod.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAVAC="${TESTJAVA}"/bin/javac
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} \
|
||||||
|
-javaagent:RedefineClassWithNativeMethodAgent.jar=java/lang/Thread.class \
|
||||||
|
-classpath "${TESTCLASSES}" RedefineClassWithNativeMethodApp \
|
||||||
|
> output.log 2>&1
|
||||||
|
result=$?
|
||||||
|
|
||||||
|
cat output.log
|
||||||
|
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "PASS: RedefineClassWithNativeMethodApp exited with status of 0."
|
||||||
|
else
|
||||||
|
echo "FAIL: RedefineClassWithNativeMethodApp exited with status of $result"
|
||||||
|
exit "$result"
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESG="Exception"
|
||||||
|
grep "$MESG" output.log
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "FAIL: found '$MESG' in the test output"
|
||||||
|
result=1
|
||||||
|
else
|
||||||
|
echo "PASS: did NOT find '$MESG' in the test output"
|
||||||
|
result=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $result
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
import java.net.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class RedefineClassWithNativeMethodAgent {
|
||||||
|
static Class clz;
|
||||||
|
|
||||||
|
// just read the original class and redefine it via a Timer
|
||||||
|
public static void premain(String agentArgs, final Instrumentation inst) throws Exception {
|
||||||
|
String s = agentArgs.substring(0, agentArgs.indexOf(".class"));
|
||||||
|
clz = Class.forName(s.replace('/', '.'));
|
||||||
|
ClassLoader loader =
|
||||||
|
RedefineClassWithNativeMethodAgent.class.getClassLoader();
|
||||||
|
URL classURL = loader.getResource(agentArgs);
|
||||||
|
if (classURL == null) {
|
||||||
|
throw new Exception("Cannot find class: " + agentArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int redefineLength;
|
||||||
|
InputStream redefineStream;
|
||||||
|
|
||||||
|
System.out.println("Reading test class from " + classURL);
|
||||||
|
if (classURL.getProtocol().equals("file")) {
|
||||||
|
File f = new File(classURL.getFile());
|
||||||
|
redefineStream = new FileInputStream(f);
|
||||||
|
redefineLength = (int) f.length();
|
||||||
|
} else {
|
||||||
|
URLConnection conn = classURL.openConnection();
|
||||||
|
redefineStream = conn.getInputStream();
|
||||||
|
redefineLength = conn.getContentLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
final byte[] buffer = new byte[redefineLength];
|
||||||
|
new BufferedInputStream(redefineStream).read(buffer);
|
||||||
|
new Timer(true).schedule(new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
System.out.println("Instrumenting");
|
||||||
|
ClassDefinition cld = new ClassDefinition(clz, buffer);
|
||||||
|
inst.redefineClasses(new ClassDefinition[] { cld });
|
||||||
|
}
|
||||||
|
catch (Exception e) { e.printStackTrace(); }
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RedefineClassWithNativeMethodApp {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
try {
|
||||||
|
// give the agent a chance to redefine the target class
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Creating instance of " +
|
||||||
|
RedefineClassWithNativeMethodAgent.clz);
|
||||||
|
RedefineClassWithNativeMethodAgent.clz.newInstance();
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
82
jdk/test/java/lang/instrument/RedefineMethodAddInvoke.sh
Normal file
82
jdk/test/java/lang/instrument/RedefineMethodAddInvoke.sh
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 6667089
|
||||||
|
# @summary Reflexive invocation of newly added methods broken.
|
||||||
|
# @author Daniel D. Daugherty
|
||||||
|
#
|
||||||
|
# @run shell MakeJAR3.sh RedefineMethodAddInvokeAgent 'Can-Redefine-Classes: true'
|
||||||
|
# @run build RedefineMethodAddInvokeApp
|
||||||
|
# @run shell RedefineMethodAddInvoke.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAVAC="${TESTJAVA}"/bin/javac
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_1.java \
|
||||||
|
RedefineMethodAddInvokeTarget.java
|
||||||
|
"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java
|
||||||
|
mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_1.java
|
||||||
|
mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_1.class
|
||||||
|
|
||||||
|
cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_2.java \
|
||||||
|
RedefineMethodAddInvokeTarget.java
|
||||||
|
"${JAVAC}" -d . RedefineMethodAddInvokeTarget.java
|
||||||
|
mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_2.java
|
||||||
|
mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_2.class
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} -javaagent:RedefineMethodAddInvokeAgent.jar \
|
||||||
|
-classpath "${TESTCLASSES}" RedefineMethodAddInvokeApp > output.log 2>&1
|
||||||
|
cat output.log
|
||||||
|
|
||||||
|
MESG="Exception"
|
||||||
|
grep "$MESG" output.log
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "FAIL: found '$MESG' in the test output"
|
||||||
|
result=1
|
||||||
|
else
|
||||||
|
echo "PASS: did NOT find '$MESG' in the test output"
|
||||||
|
result=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $result
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
|
||||||
|
public class RedefineMethodAddInvokeAgent {
|
||||||
|
private static Instrumentation instrumentation;
|
||||||
|
|
||||||
|
private RedefineMethodAddInvokeAgent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void premain(String agentArgs, Instrumentation inst) {
|
||||||
|
System.out.println("Hello from RedefineMethodAddInvokeAgent!");
|
||||||
|
System.out.println("isRedefineClassesSupported()=" +
|
||||||
|
inst.isRedefineClassesSupported());
|
||||||
|
|
||||||
|
instrumentation = inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Instrumentation getInstrumentation() {
|
||||||
|
return instrumentation;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.instrument.*;
|
||||||
|
|
||||||
|
public class RedefineMethodAddInvokeApp {
|
||||||
|
public static void main(String args[]) throws Exception {
|
||||||
|
System.out.println("Hello from RedefineMethodAddInvokeApp!");
|
||||||
|
|
||||||
|
new RedefineMethodAddInvokeApp().doTest();
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTest() throws Exception {
|
||||||
|
RedefineMethodAddInvokeTarget target =
|
||||||
|
new RedefineMethodAddInvokeTarget();
|
||||||
|
|
||||||
|
System.out.println("RedefineMethodAddInvokeApp: invoking myMethod()");
|
||||||
|
target.test(0); // invoke the original myMethod()
|
||||||
|
|
||||||
|
// add myMethod1()
|
||||||
|
do_redefine(1);
|
||||||
|
|
||||||
|
System.out.println("RedefineMethodAddInvokeApp: invoking myMethod1()");
|
||||||
|
target.test(1); // invoke myMethod1()
|
||||||
|
|
||||||
|
// add myMethod2()
|
||||||
|
do_redefine(2);
|
||||||
|
|
||||||
|
System.out.println("RedefineMethodAddInvokeApp: invoking myMethod2()");
|
||||||
|
target.test(2); // invoke myMethod2()
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void do_redefine(int counter) throws Exception {
|
||||||
|
File f = new File("RedefineMethodAddInvokeTarget_" + counter +
|
||||||
|
".class");
|
||||||
|
System.out.println("Reading test class from " + f);
|
||||||
|
InputStream redefineStream = new FileInputStream(f);
|
||||||
|
|
||||||
|
byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream);
|
||||||
|
|
||||||
|
ClassDefinition redefineParamBlock = new ClassDefinition(
|
||||||
|
RedefineMethodAddInvokeTarget.class, redefineBuffer);
|
||||||
|
|
||||||
|
RedefineMethodAddInvokeAgent.getInstrumentation().redefineClasses(
|
||||||
|
new ClassDefinition[] {redefineParamBlock});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class RedefineMethodAddInvokeTarget {
|
||||||
|
public void test(int counter) throws Exception {
|
||||||
|
Method method = getClass().getDeclaredMethod("myMethod" +
|
||||||
|
(counter == 0 ? "" : counter));
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void myMethod() {
|
||||||
|
System.out.println("Hello from the original myMethod()!");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class RedefineMethodAddInvokeTarget {
|
||||||
|
public void test(int counter) throws Exception {
|
||||||
|
Method method = getClass().getDeclaredMethod("myMethod" +
|
||||||
|
(counter == 0 ? "" : counter));
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void myMethod() {
|
||||||
|
System.out.println("Hello from the non-EMCP myMethod()!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void myMethod1() {
|
||||||
|
System.out.println("Hello from myMethod1()!");
|
||||||
|
System.out.println("Calling myMethod() from myMethod1():");
|
||||||
|
myMethod();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class RedefineMethodAddInvokeTarget {
|
||||||
|
public void test(int counter) throws Exception {
|
||||||
|
Method method = getClass().getDeclaredMethod("myMethod" +
|
||||||
|
(counter == 0 ? "" : counter));
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void myMethod() {
|
||||||
|
System.out.println("Hello from the non-EMCP again myMethod()!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void myMethod1() {
|
||||||
|
System.out.println("Hello from myMethod1()!");
|
||||||
|
System.out.println("Calling myMethod() from myMethod1():");
|
||||||
|
myMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void myMethod2() {
|
||||||
|
System.out.println("Hello from myMethod2()!");
|
||||||
|
System.out.println("Calling myMethod1() from myMethod2():");
|
||||||
|
myMethod1();
|
||||||
|
}
|
||||||
|
}
|
@ -27,7 +27,7 @@
|
|||||||
* @summary test retransformClasses
|
* @summary test retransformClasses
|
||||||
* @author Robert Field, Sun Microsystems
|
* @author Robert Field, Sun Microsystems
|
||||||
*
|
*
|
||||||
* @run shell MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true'
|
* @run shell/timeout=240 MakeJAR2.sh RetransformAgent RetransformApp 'Can-Retransform-Classes: true'
|
||||||
* @run main/othervm -javaagent:RetransformAgent.jar RetransformApp
|
* @run main/othervm -javaagent:RetransformAgent.jar RetransformApp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
86
jdk/test/java/lang/instrument/StressGetObjectSizeApp.java
Normal file
86
jdk/test/java/lang/instrument/StressGetObjectSizeApp.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.instrument.Instrumentation;
|
||||||
|
|
||||||
|
public class StressGetObjectSizeApp
|
||||||
|
extends ASimpleInstrumentationTestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for StressGetObjectSizeApp.
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
public StressGetObjectSizeApp(String name)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void
|
||||||
|
main (String[] args)
|
||||||
|
throws Throwable {
|
||||||
|
ATestCaseScaffold test = new StressGetObjectSizeApp(args[0]);
|
||||||
|
test.runTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void
|
||||||
|
doRunTest()
|
||||||
|
throws Throwable {
|
||||||
|
stressGetObjectSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stressGetObjectSize() {
|
||||||
|
System.out.println("main: an object size=" +
|
||||||
|
fInst.getObjectSize(new Object()));
|
||||||
|
|
||||||
|
RoundAndRound[] threads = new RoundAndRound[10];
|
||||||
|
for (int i = 0; i < threads.length; ++i) {
|
||||||
|
threads[i] = new RoundAndRound(fInst);
|
||||||
|
threads[i].start();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(500); // let all threads get going in their loops
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
|
System.out.println("stressGetObjectSize: returning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class RoundAndRound extends Thread {
|
||||||
|
private final Instrumentation inst;
|
||||||
|
private final Object anObject;
|
||||||
|
|
||||||
|
public RoundAndRound(Instrumentation inst) {
|
||||||
|
this.inst = inst;
|
||||||
|
this.anObject = new Object();
|
||||||
|
setDaemon(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
long sum = 0;
|
||||||
|
while (true) {
|
||||||
|
sum += inst.getObjectSize(anObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
70
jdk/test/java/lang/instrument/StressGetObjectSizeTest.sh
Normal file
70
jdk/test/java/lang/instrument/StressGetObjectSizeTest.sh
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
# under the terms of the GNU General Public License version 2 only, as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
# version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
# accompanied this code).
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License version
|
||||||
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
# CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
# have any questions.
|
||||||
|
#
|
||||||
|
|
||||||
|
# @test
|
||||||
|
# @bug 6572160
|
||||||
|
# @summary stress getObjectSize() API
|
||||||
|
# @author Daniel D. Daugherty as modified from the code of fischman@google.com
|
||||||
|
#
|
||||||
|
# @run build StressGetObjectSizeApp
|
||||||
|
# @run shell MakeJAR.sh basicAgent
|
||||||
|
# @run shell StressGetObjectSizeTest.sh
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ "${TESTJAVA}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTJAVA not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTSRC}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
|
then
|
||||||
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
JAVA="${TESTJAVA}"/bin/java
|
||||||
|
|
||||||
|
"${JAVA}" ${TESTVMOPTS} -javaagent:basicAgent.jar \
|
||||||
|
-classpath "${TESTCLASSES}" StressGetObjectSizeApp StressGetObjectSizeApp \
|
||||||
|
> output.log 2>&1
|
||||||
|
cat output.log
|
||||||
|
|
||||||
|
MESG="ASSERTION FAILED"
|
||||||
|
grep "$MESG" output.log
|
||||||
|
result=$?
|
||||||
|
if [ "$result" = 0 ]; then
|
||||||
|
echo "FAIL: found '$MESG' in the test output"
|
||||||
|
result=1
|
||||||
|
else
|
||||||
|
echo "PASS: did NOT find '$MESG' in the test output"
|
||||||
|
result=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $result
|
36
jdk/test/java/lang/instrument/TestClass1.java
Normal file
36
jdk/test/java/lang/instrument/TestClass1.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Java Program
|
||||||
|
*
|
||||||
|
* @author Daryl Puryear
|
||||||
|
* @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
public class TestClass1
|
||||||
|
{
|
||||||
|
public
|
||||||
|
TestClass1()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
36
jdk/test/java/lang/instrument/TestClass2.java
Normal file
36
jdk/test/java/lang/instrument/TestClass2.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Java Program
|
||||||
|
*
|
||||||
|
* @author Daryl Puryear
|
||||||
|
* @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
public class TestClass2
|
||||||
|
{
|
||||||
|
public
|
||||||
|
TestClass2()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
36
jdk/test/java/lang/instrument/TestClass3.java
Normal file
36
jdk/test/java/lang/instrument/TestClass3.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||||
|
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||||
|
* have any questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test Java Program
|
||||||
|
*
|
||||||
|
* @author Daryl Puryear
|
||||||
|
* @copyright 1999-2004 Wily Technology, Inc. All rights reserved.
|
||||||
|
*/
|
||||||
|
public class TestClass3
|
||||||
|
{
|
||||||
|
public
|
||||||
|
TestClass3()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -79,6 +79,12 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
protected static final int TOTAL_THREADS = MAX_TRANS - MIN_TRANS + 1;
|
protected static final int TOTAL_THREADS = MAX_TRANS - MIN_TRANS + 1;
|
||||||
|
|
||||||
private byte[] fDummyClassBytes;
|
private byte[] fDummyClassBytes;
|
||||||
|
// fCheckedTransformers is a Vector that is used to verify
|
||||||
|
// that the transform() function is called in the same
|
||||||
|
// order in which the transformers were added to the
|
||||||
|
// TransformerManager. The test currently verifies that all
|
||||||
|
// transformers for a specific worker thread are in
|
||||||
|
// increasing order by index value.
|
||||||
private Vector fCheckedTransformers;
|
private Vector fCheckedTransformers;
|
||||||
private Instrumentation fInstrumentation;
|
private Instrumentation fInstrumentation;
|
||||||
private int fFinished;
|
private int fFinished;
|
||||||
@ -131,9 +137,16 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
threads[i].start();
|
threads[i].start();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!exec.fDone)
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Don't use a direct field getter.
|
||||||
|
while (!exec.isDone())
|
||||||
{
|
{
|
||||||
Thread.currentThread().yield();
|
// Effective Java - Item 51: Don't depend on the thread scheduler
|
||||||
|
// Use sleep() instead of yield().
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assertTrue(finalCheck());
|
assertTrue(finalCheck());
|
||||||
|
|
||||||
@ -169,13 +182,17 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
this.fExec = exec;
|
this.fExec = exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Document a synchronized setter.
|
||||||
protected synchronized void
|
protected synchronized void
|
||||||
threadFinished(Thread t)
|
threadFinished(Thread t)
|
||||||
{
|
{
|
||||||
fFinished++;
|
fFinished++;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Provide synchronized getter.
|
||||||
|
protected synchronized boolean
|
||||||
threadsDone()
|
threadsDone()
|
||||||
{
|
{
|
||||||
return fFinished == TOTAL_THREADS;
|
return fFinished == TOTAL_THREADS;
|
||||||
@ -188,7 +205,9 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
protected boolean
|
protected boolean
|
||||||
testCompleted()
|
testCompleted()
|
||||||
{
|
{
|
||||||
return getExecThread().fDone;
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Don't use direct field getter.
|
||||||
|
return getExecThread().isDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -264,11 +283,19 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
private void
|
private void
|
||||||
executeTransform()
|
executeTransform()
|
||||||
{
|
{
|
||||||
fCheckedTransformers.clear();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ClassDefinition cd = new ClassDefinition(DummyClass.class, fDummyClassBytes);
|
ClassDefinition cd = new ClassDefinition(DummyClass.class, fDummyClassBytes);
|
||||||
|
|
||||||
|
// When the ClassDefinition above is created for the first
|
||||||
|
// time and every time redefineClasses() below is called,
|
||||||
|
// the transform() function is called for each registered
|
||||||
|
// transformer. We only want one complete set of calls to
|
||||||
|
// be logged in the fCheckedTransformers Vector so we clear
|
||||||
|
// any calls logged for ClassDefinition above and just use
|
||||||
|
// the ones logged for redefineClasses() below.
|
||||||
|
fCheckedTransformers.clear();
|
||||||
|
|
||||||
getInstrumentation().redefineClasses(new ClassDefinition[]{ cd });
|
getInstrumentation().redefineClasses(new ClassDefinition[]{ cd });
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e)
|
catch (ClassNotFoundException e)
|
||||||
@ -325,6 +352,18 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
{
|
{
|
||||||
private boolean fDone = false;
|
private boolean fDone = false;
|
||||||
|
|
||||||
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Provide a synchronized getter.
|
||||||
|
private synchronized boolean isDone() {
|
||||||
|
return fDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Provide a synchronized setter.
|
||||||
|
private synchronized void setIsDone() {
|
||||||
|
fDone = true;
|
||||||
|
}
|
||||||
|
|
||||||
public void
|
public void
|
||||||
run()
|
run()
|
||||||
{
|
{
|
||||||
@ -335,7 +374,9 @@ public class TransformerManagementThreadAddTests extends ATestCaseScaffold
|
|||||||
|
|
||||||
// Do a final check for good measure
|
// Do a final check for good measure
|
||||||
executeTransform();
|
executeTransform();
|
||||||
fDone = true;
|
// Effective Java - Item 48: Synchronize access to shared mutable data
|
||||||
|
// Don't use direct field setter.
|
||||||
|
setIsDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,10 +27,9 @@
|
|||||||
* @summary multi-thread test to exercise sync and contention for removes to transformer registry
|
* @summary multi-thread test to exercise sync and contention for removes to transformer registry
|
||||||
* @author Gabriel Adauto, Wily Technology
|
* @author Gabriel Adauto, Wily Technology
|
||||||
*
|
*
|
||||||
* @ignore Disabled until race condition which hangs test can be fixed.
|
|
||||||
* @run build TransformerManagementThreadRemoveTests
|
* @run build TransformerManagementThreadRemoveTests
|
||||||
* @run shell MakeJAR.sh basicAgent
|
* @run shell MakeJAR.sh redefineAgent
|
||||||
* @run main/othervm -javaagent:basicAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests
|
* @run main/othervm -javaagent:redefineAgent.jar TransformerManagementThreadRemoveTests TransformerManagementThreadRemoveTests
|
||||||
*/
|
*/
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -87,7 +86,12 @@ public class TransformerManagementThreadRemoveTests
|
|||||||
|
|
||||||
while (!testCompleted())
|
while (!testCompleted())
|
||||||
{
|
{
|
||||||
Thread.currentThread().yield();
|
// Effective Java - Item 51: Don't depend on the thread scheduler
|
||||||
|
// Use sleep() instead of yield().
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assertTrue(finalCheck());
|
assertTrue(finalCheck());
|
||||||
|
|
||||||
|
@ -26,14 +26,14 @@
|
|||||||
# @summary Unit tests for appendToBootstrapClassLoaderSearch and
|
# @summary Unit tests for appendToBootstrapClassLoaderSearch and
|
||||||
# appendToSystemClasLoaderSearch methods.
|
# appendToSystemClasLoaderSearch methods.
|
||||||
#
|
#
|
||||||
# @run shell CircularityErrorTest.sh
|
# @run shell/timeout=240 CircularityErrorTest.sh
|
||||||
|
|
||||||
if [ "${TESTSRC}" = "" ]
|
if [ "${TESTSRC}" = "" ]
|
||||||
then
|
then
|
||||||
echo "TESTSRC not set. Test cannot execute. Failed."
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. ${TESTSRC}/CommonSetup.sh
|
. ${TESTSRC}/CommonSetup.sh
|
||||||
|
|
||||||
# Setup to create circularity condition
|
# Setup to create circularity condition
|
||||||
@ -71,5 +71,5 @@ $JAR -cfm "${TESTCLASSES}"/CircularityErrorTest.jar "${MANIFEST}" \
|
|||||||
-C "${TESTCLASSES}" CircularityErrorTest.class
|
-C "${TESTCLASSES}" CircularityErrorTest.class
|
||||||
|
|
||||||
# Finally we run the test
|
# Finally we run the test
|
||||||
(cd "${TESTCLASSES}";
|
(cd "${TESTCLASSES}";
|
||||||
$JAVA -javaagent:CircularityErrorTest.jar CircularityErrorTest)
|
$JAVA ${TESTVMOPTS} -javaagent:CircularityErrorTest.jar CircularityErrorTest)
|
||||||
|
@ -34,11 +34,11 @@ then
|
|||||||
echo "TESTSRC not set. Test cannot execute. Failed."
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. ${TESTSRC}/CommonSetup.sh
|
. ${TESTSRC}/CommonSetup.sh
|
||||||
|
|
||||||
# Create Foo and Bar
|
# Create Foo and Bar
|
||||||
# Foo has a reference to Bar but we deleted Bar so that
|
# Foo has a reference to Bar but we deleted Bar so that
|
||||||
# a NoClassDefFoundError will be thrown when Foo tries to
|
# a NoClassDefFoundError will be thrown when Foo tries to
|
||||||
# resolve the reference to Bar
|
# resolve the reference to Bar
|
||||||
|
|
||||||
@ -53,11 +53,11 @@ cat << EOF > "${FOO}"
|
|||||||
public class Foo {
|
public class Foo {
|
||||||
public static boolean doSomething() {
|
public static boolean doSomething() {
|
||||||
try {
|
try {
|
||||||
Bar b = new Bar();
|
Bar b = new Bar();
|
||||||
return true;
|
return true;
|
||||||
} catch (NoClassDefFoundError x) {
|
} catch (NoClassDefFoundError x) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
@ -79,5 +79,5 @@ $JAR -cfm "${TESTCLASSES}"/ClassUnloadTest.jar "${MANIFEST}" \
|
|||||||
|
|
||||||
# Finally we run the test
|
# Finally we run the test
|
||||||
(cd "${TESTCLASSES}"; \
|
(cd "${TESTCLASSES}"; \
|
||||||
$JAVA -Xverify:none -XX:+TraceClassUnloading -javaagent:ClassUnloadTest.jar \
|
$JAVA ${TESTVMOPTS} -Xverify:none -XX:+TraceClassUnloading \
|
||||||
ClassUnloadTest "${OTHERDIR}" Bar.jar)
|
-javaagent:ClassUnloadTest.jar ClassUnloadTest "${OTHERDIR}" Bar.jar)
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
#%E
|
|
||||||
#
|
#
|
||||||
# Common setup for unit tests. Setups up the following variables:
|
# Common setup for unit tests. Setups up the following variables:
|
||||||
#
|
#
|
||||||
@ -66,7 +65,7 @@ then
|
|||||||
echo "TESTSRC not set. Test cannot execute. Failed."
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${TESTCLASSES}" = "" ]
|
if [ "${TESTCLASSES}" = "" ]
|
||||||
then
|
then
|
||||||
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
echo "TESTCLASSES not set. Test cannot execute. Failed."
|
||||||
|
@ -23,24 +23,24 @@
|
|||||||
# have any questions.
|
# have any questions.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
# @test
|
# @test
|
||||||
# @bug 6173575 6388987
|
# @bug 6173575 6388987
|
||||||
# @summary Unit tests for appendToBootstrapClassLoaderSearch and
|
# @summary Unit tests for appendToBootstrapClassLoaderSearch and
|
||||||
# appendToSystemClasLoaderSearch methods.
|
# appendToSystemClasLoaderSearch methods.
|
||||||
#
|
#
|
||||||
# @build Agent AgentSupport BootSupport BasicTest PrematureLoadTest DynamicTest
|
# @build Agent AgentSupport BootSupport BasicTest PrematureLoadTest DynamicTest
|
||||||
# @run shell run_tests.sh
|
# @run shell/timeout=240 run_tests.sh
|
||||||
|
|
||||||
if [ "${TESTSRC}" = "" ]
|
if [ "${TESTSRC}" = "" ]
|
||||||
then
|
then
|
||||||
echo "TESTSRC not set. Test cannot execute. Failed."
|
echo "TESTSRC not set. Test cannot execute. Failed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. ${TESTSRC}/CommonSetup.sh
|
. ${TESTSRC}/CommonSetup.sh
|
||||||
|
|
||||||
|
|
||||||
# Simple tests
|
# Simple tests
|
||||||
|
|
||||||
echo "Creating jar files for simple tests..."
|
echo "Creating jar files for simple tests..."
|
||||||
@ -50,13 +50,13 @@ cd ${TESTCLASSES}
|
|||||||
"$JAR" -cfm Agent.jar "${TESTSRC}"/manifest.mf Agent.class
|
"$JAR" -cfm Agent.jar "${TESTSRC}"/manifest.mf Agent.class
|
||||||
"$JAR" -cf AgentSupport.jar AgentSupport.class
|
"$JAR" -cf AgentSupport.jar AgentSupport.class
|
||||||
"$JAR" -cf BootSupport.jar BootSupport.class
|
"$JAR" -cf BootSupport.jar BootSupport.class
|
||||||
"$JAR" -cf SimpleTests.jar BasicTest.class PrematureLoadTest.class
|
"$JAR" -cf SimpleTests.jar BasicTest.class PrematureLoadTest.class
|
||||||
|
|
||||||
failures=0
|
failures=0
|
||||||
|
|
||||||
go() {
|
go() {
|
||||||
echo ''
|
echo ''
|
||||||
sh -xc "$JAVA -javaagent:Agent.jar -classpath SimpleTests.jar $1 $2 $3" 2>&1
|
sh -xc "$JAVA ${TESTVMOPTS} -javaagent:Agent.jar -classpath SimpleTests.jar $1 $2 $3" 2>&1
|
||||||
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ mkdir tmp
|
|||||||
"${JAVAC}" -d tmp "${TESTSRC}"/Tracer.java
|
"${JAVAC}" -d tmp "${TESTSRC}"/Tracer.java
|
||||||
(cd tmp; "${JAR}" cf ../Tracer.jar org/tools/Tracer.class)
|
(cd tmp; "${JAR}" cf ../Tracer.jar org/tools/Tracer.class)
|
||||||
|
|
||||||
# InstrumentedApplication is Application+instrmentation - don't copy as
|
# InstrumentedApplication is Application+instrmentation - don't copy as
|
||||||
# we don't want the original file permission
|
# we don't want the original file permission
|
||||||
|
|
||||||
cat "${TESTSRC}"/InstrumentedApplication.java > ./Application.java
|
cat "${TESTSRC}"/InstrumentedApplication.java > ./Application.java
|
||||||
@ -85,11 +85,11 @@ mv Application.class InstrumentedApplication.bytes
|
|||||||
cp "${TESTSRC}"/Application.java .
|
cp "${TESTSRC}"/Application.java .
|
||||||
"${JAVAC}" -d . Application.java
|
"${JAVAC}" -d . Application.java
|
||||||
|
|
||||||
sh -xc "$JAVA -classpath . -javaagent:Agent.jar DynamicTest" 2>&1
|
sh -xc "$JAVA ${TESTVMOPTS} -classpath . -javaagent:Agent.jar DynamicTest" 2>&1
|
||||||
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
||||||
|
|
||||||
# Repeat test with security manager
|
# Repeat test with security manager
|
||||||
sh -xc "$JAVA -classpath . -javaagent:Agent.jar -Djava.security.manager DynamicTest" 2>&1
|
sh -xc "$JAVA ${TESTVMOPTS} -classpath . -javaagent:Agent.jar -Djava.security.manager DynamicTest" 2>&1
|
||||||
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user