34
35 static jlong timeout = 0;
36
37 static char segment1[3000] = "";
38 static char segment2[3000] = "";
39
40 static const char* const illegal_segments[] = {"", "tmp/"};
41
42 jboolean use_segment2 = JNI_FALSE;
43
44 jvmtiPhase jvmti_phase_to_check = JVMTI_PHASE_ONLOAD;
45
46 /* ============================================================================= */
47
48 /**
49 * Add segment to bootstrap classloader path.
50 * @returns NSK_FALSE if any error occured.
51 */
52 static int addSegment(jvmtiEnv* jvmti, const char segment[], const char where[]) {
53 NSK_DISPLAY1("Add segment: \"%s\"\n", segment);
54 if (!NSK_JVMTI_VERIFY(
55 NSK_CPP_STUB2(AddToSystemClassLoaderSearch, jvmti, segment))) {
56 NSK_COMPLAIN1("TEST FAILURE: failed to add segment %s\n", segment);
57 return NSK_FALSE;
58 }
59 NSK_DISPLAY0(" ... added\n");
60
61 return NSK_TRUE;
62 }
63
64 /**
65 * Try to add illegal segment to bootstrap classloader path and check that expected error
66 * (expectedError) is returned.
67 * @returns NSK_FALSE if no error or wronf error is occured.
68 */
69 static int addIllegalSegment(jvmtiEnv* jvmti, const char segment[], const char where[], jvmtiError expectedError) {
70 NSK_DISPLAY1("Add illegal segment: \"%s\"\n", segment);
71 if (!NSK_JVMTI_VERIFY_CODE(expectedError,
72 NSK_CPP_STUB2(AddToSystemClassLoaderSearch, jvmti, segment))) {
73
74 NSK_COMPLAIN2("TEST FAILURE: got wrong error when tried to add segment %s (expected error=%s)\n",
75 segment, TranslateError(expectedError));
76 return NSK_FALSE;
77 }
78 NSK_DISPLAY0(" ... not added\n");
79
80 return NSK_TRUE;
81 }
82
83 /*
84 * Check that attempt to add illegal segment causes the error.
85 */
86 static void checkLivePhaseForIllegalArgs(jvmtiEnv* jvmti, const char where[]) {
87 size_t i;
88
89 for (i = 0; i < sizeof(illegal_segments)/sizeof(char*); i++) {
90 if (!addIllegalSegment(jvmti, illegal_segments[i], where, JVMTI_ERROR_ILLEGAL_ARGUMENT)) {
91 nsk_jvmti_setFailStatus();
92 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
106 if (!addSegment(jvmti, segment1, "VMInit()")) {
107 nsk_jvmti_setFailStatus();
108 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
109 }
110
111 if (use_segment2 == JNI_FALSE) return;
112
113 if (!addSegment(jvmti, segment2, "VMInit()")) {
114 nsk_jvmti_setFailStatus();
115 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
116 }
117 }
118
119 /*
120 * Check that it is possible to add to the boot class path before VMDeath event return.
121 */
122 void JNICALL
123 callbackVMDeath(jvmtiEnv *jvmti, JNIEnv* jni) {
124 jvmtiPhase phase;
125
126 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase, jvmti, &phase))) {
127 NSK_COMPLAIN0("TEST FAILURE: unable to get phase\n");
128 nsk_jvmti_setFailStatus();
129 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
130 }
131
132 if (!NSK_VERIFY(phase == JVMTI_PHASE_LIVE)) {
133 NSK_DISPLAY0(">>> Testcase #1: Add bootstrap class load segment(s) in VMDeath (live phase)\n");
134
135 // At first check that it is not possible to add anything other than an existing JAR file
136 checkLivePhaseForIllegalArgs(jvmti, "VMDeath()");
137
138 /* Check, that it is possible to add a JAR file containing a class that is already
139 * loaded (or is in the process of being loaded) by a _bootstrap_ class loader.
140 */
141
142 if (!addSegment(jvmti, segment1, "VMDeath()")) {
143 nsk_jvmti_setFailStatus();
144 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
145 }
146
201 if (!addSegment(jvmti, segment1, "Agent_OnLoad()")) {
202 return JNI_ERR;
203 }
204
205 if (!addSegment(jvmti, segment2, "Agent_OnLoad()")) {
206 return JNI_ERR;
207 }
208
209 return JNI_OK;
210 }
211
212 /* For Live phase enable events and set callbacks for them */
213 NSK_DISPLAY1("Set callback for events: %s\n", "VM_INIT, VM_DEATH");
214 {
215 jvmtiEventCallbacks eventCallbacks;
216 memset(&eventCallbacks, 0, sizeof(eventCallbacks));
217
218 eventCallbacks.VMInit = callbackVMInit;
219 eventCallbacks.VMDeath = callbackVMDeath;
220
221 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks, jvmti,
222 &eventCallbacks, sizeof(eventCallbacks)))) {
223 return JNI_ERR;
224 }
225 }
226 NSK_DISPLAY0(" ... set\n");
227
228 NSK_DISPLAY1("Enable events: %s\n", "VM_INIT, VM_DEATH");
229 {
230
231 jvmtiEvent eventsList[] = { JVMTI_EVENT_VM_INIT, JVMTI_EVENT_VM_DEATH };
232 if (!NSK_VERIFY(nsk_jvmti_enableEvents(
233 JVMTI_ENABLE, sizeof(eventsList)/sizeof(jvmtiEvent), eventsList, NULL))) {
234 return JNI_ERR;
235 }
236 }
237 NSK_DISPLAY0(" ... enabled\n");
238
239 return JNI_OK;
240 }
241
242 /* ============================================================================= */
|
34
35 static jlong timeout = 0;
36
37 static char segment1[3000] = "";
38 static char segment2[3000] = "";
39
40 static const char* const illegal_segments[] = {"", "tmp/"};
41
42 jboolean use_segment2 = JNI_FALSE;
43
44 jvmtiPhase jvmti_phase_to_check = JVMTI_PHASE_ONLOAD;
45
46 /* ============================================================================= */
47
48 /**
49 * Add segment to bootstrap classloader path.
50 * @returns NSK_FALSE if any error occured.
51 */
52 static int addSegment(jvmtiEnv* jvmti, const char segment[], const char where[]) {
53 NSK_DISPLAY1("Add segment: \"%s\"\n", segment);
54 if (!NSK_JVMTI_VERIFY(jvmti->AddToSystemClassLoaderSearch(segment))) {
55 NSK_COMPLAIN1("TEST FAILURE: failed to add segment %s\n", segment);
56 return NSK_FALSE;
57 }
58 NSK_DISPLAY0(" ... added\n");
59
60 return NSK_TRUE;
61 }
62
63 /**
64 * Try to add illegal segment to bootstrap classloader path and check that expected error
65 * (expectedError) is returned.
66 * @returns NSK_FALSE if no error or wronf error is occured.
67 */
68 static int addIllegalSegment(jvmtiEnv* jvmti, const char segment[], const char where[], jvmtiError expectedError) {
69 NSK_DISPLAY1("Add illegal segment: \"%s\"\n", segment);
70 if (!NSK_JVMTI_VERIFY_CODE(expectedError, jvmti->AddToSystemClassLoaderSearch(segment))) {
71
72 NSK_COMPLAIN2("TEST FAILURE: got wrong error when tried to add segment %s (expected error=%s)\n",
73 segment, TranslateError(expectedError));
74 return NSK_FALSE;
75 }
76 NSK_DISPLAY0(" ... not added\n");
77
78 return NSK_TRUE;
79 }
80
81 /*
82 * Check that attempt to add illegal segment causes the error.
83 */
84 static void checkLivePhaseForIllegalArgs(jvmtiEnv* jvmti, const char where[]) {
85 size_t i;
86
87 for (i = 0; i < sizeof(illegal_segments)/sizeof(char*); i++) {
88 if (!addIllegalSegment(jvmti, illegal_segments[i], where, JVMTI_ERROR_ILLEGAL_ARGUMENT)) {
89 nsk_jvmti_setFailStatus();
90 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
104 if (!addSegment(jvmti, segment1, "VMInit()")) {
105 nsk_jvmti_setFailStatus();
106 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
107 }
108
109 if (use_segment2 == JNI_FALSE) return;
110
111 if (!addSegment(jvmti, segment2, "VMInit()")) {
112 nsk_jvmti_setFailStatus();
113 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
114 }
115 }
116
117 /*
118 * Check that it is possible to add to the boot class path before VMDeath event return.
119 */
120 void JNICALL
121 callbackVMDeath(jvmtiEnv *jvmti, JNIEnv* jni) {
122 jvmtiPhase phase;
123
124 if (!NSK_JVMTI_VERIFY(jvmti->GetPhase(&phase))) {
125 NSK_COMPLAIN0("TEST FAILURE: unable to get phase\n");
126 nsk_jvmti_setFailStatus();
127 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
128 }
129
130 if (!NSK_VERIFY(phase == JVMTI_PHASE_LIVE)) {
131 NSK_DISPLAY0(">>> Testcase #1: Add bootstrap class load segment(s) in VMDeath (live phase)\n");
132
133 // At first check that it is not possible to add anything other than an existing JAR file
134 checkLivePhaseForIllegalArgs(jvmti, "VMDeath()");
135
136 /* Check, that it is possible to add a JAR file containing a class that is already
137 * loaded (or is in the process of being loaded) by a _bootstrap_ class loader.
138 */
139
140 if (!addSegment(jvmti, segment1, "VMDeath()")) {
141 nsk_jvmti_setFailStatus();
142 NSK_BEFORE_TRACE(exit(nsk_jvmti_getStatus()));
143 }
144
199 if (!addSegment(jvmti, segment1, "Agent_OnLoad()")) {
200 return JNI_ERR;
201 }
202
203 if (!addSegment(jvmti, segment2, "Agent_OnLoad()")) {
204 return JNI_ERR;
205 }
206
207 return JNI_OK;
208 }
209
210 /* For Live phase enable events and set callbacks for them */
211 NSK_DISPLAY1("Set callback for events: %s\n", "VM_INIT, VM_DEATH");
212 {
213 jvmtiEventCallbacks eventCallbacks;
214 memset(&eventCallbacks, 0, sizeof(eventCallbacks));
215
216 eventCallbacks.VMInit = callbackVMInit;
217 eventCallbacks.VMDeath = callbackVMDeath;
218
219 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)))) {
220 return JNI_ERR;
221 }
222 }
223 NSK_DISPLAY0(" ... set\n");
224
225 NSK_DISPLAY1("Enable events: %s\n", "VM_INIT, VM_DEATH");
226 {
227
228 jvmtiEvent eventsList[] = { JVMTI_EVENT_VM_INIT, JVMTI_EVENT_VM_DEATH };
229 if (!NSK_VERIFY(nsk_jvmti_enableEvents(
230 JVMTI_ENABLE, sizeof(eventsList)/sizeof(jvmtiEvent), eventsList, NULL))) {
231 return JNI_ERR;
232 }
233 }
234 NSK_DISPLAY0(" ... enabled\n");
235
236 return JNI_OK;
237 }
238
239 /* ============================================================================= */
|