70 }
71
72 Options* nsk_jvmti_aod_getMultiagentsOptions(jvmtiEnv *jvmti) {
73 int i;
74 for (i = 0; i < multiagentsCount; i++) {
75 if (multiagentsOptions[i].jvmti == jvmti) {
76 return multiagentsOptions[i].options;
77 }
78 }
79
80 NSK_COMPLAIN1("Options for jvmtiEnv %p weren't found\n", jvmti);
81
82 return NULL;
83 }
84
85 /*
86 * Auxiliary functions
87 */
88
89 void nsk_jvmti_aod_deallocate(jvmtiEnv *jvmti, unsigned char* mem) {
90 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(Deallocate, jvmti, mem))) {
91 NSK_COMPLAIN0("Deallocate failed\n");
92
93 /*
94 * if deallocate fails it isn't critical and test execution can continue without problems,
95 * just call nsk_aod_internal_error to inform framework about this error
96 */
97 nsk_aod_internal_error();
98 }
99 }
100
101 int nsk_jvmti_aod_getClassName(jvmtiEnv *jvmti, jclass klass, char classNameBuffer[]) {
102 char* className;
103
104 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(GetClassSignature, jvmti, klass, &className, NULL))) {
105 NSK_COMPLAIN0("Failed to get class name\n");
106 classNameBuffer[0] = '\0';
107 return NSK_FALSE;
108 } else {
109 strcpy(classNameBuffer, className);
110
111 nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)className);
112
113 return NSK_TRUE;
114 }
115 }
116
117 int nsk_jvmti_aod_getThreadName(jvmtiEnv * jvmti, jthread thread, char threadNameBuffer[]) {
118 jvmtiThreadInfo info;
119 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(GetThreadInfo, jvmti, thread, &info))){
120 NSK_COMPLAIN0("Failed to get thread info\n");
121 threadNameBuffer[0] = '\0';
122 return NSK_FALSE;
123 } else {
124 strcpy(threadNameBuffer, info.name);
125
126 nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)info.name);
127
128 return NSK_TRUE;
129 }
130 }
131
132 // events enabling/disabling
133
134 int nsk_jvmti_aod_disableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) {
135 int i;
136 int status = NSK_TRUE;
137
138 for (i = 0; i < eventsNumber; i++) {
139 if (!nsk_jvmti_aod_disableEvent(jvmti, events[i])) {
144 return status;
145 }
146
147 int nsk_jvmti_aod_enableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) {
148 int i;
149 for (i = 0; i < eventsNumber; i++) {
150 if (!nsk_jvmti_aod_enableEvent(jvmti, events[i]))
151 return NSK_FALSE;
152 }
153
154 return NSK_TRUE;
155 }
156
157 // java threads creation
158
159 jthread nsk_jvmti_aod_createThread(JNIEnv *jni) {
160 jclass klass ;
161 jmethodID threadConstructor;
162 jthread thread;
163
164 if (!NSK_JNI_VERIFY(jni,
165 (klass = NSK_CPP_STUB2(FindClass, jni, "java/lang/Thread")) != NULL )) {
166 NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n");
167 return NULL;
168 }
169 if (!NSK_JNI_VERIFY(jni,
170 (threadConstructor = NSK_CPP_STUB4(GetMethodID, jni, klass, "<init>", "()V") ) != NULL )) {
171 NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n");
172 return NULL;
173 }
174
175 if (!NSK_JNI_VERIFY (jni,
176 (thread = NSK_CPP_STUB4(NewObject, jni, klass, threadConstructor, NULL)) != NULL ) ) {
177 NSK_COMPLAIN0("Failed to create Thread object\n");
178 return NULL;
179 }
180
181 if (!NSK_JNI_VERIFY(jni, (thread =
182 NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) {
183 NSK_COMPLAIN0("Failed to create global reference\n");
184 return NULL;
185 }
186
187 return thread;
188 }
189
190 jthread nsk_jvmti_aod_createThreadWithName(JNIEnv *jni, const char* threadName) {
191 jclass klass ;
192 jmethodID threadConstructor;
193 jthread thread;
194 jstring threadNameString;
195
196 if (!NSK_JNI_VERIFY(jni, (threadNameString =
197 NSK_CPP_STUB2(NewStringUTF, jni, threadName)) != NULL))
198 return NULL;
199
200 if (!NSK_JNI_VERIFY(jni,
201 (klass = NSK_CPP_STUB2(FindClass, jni, "java/lang/Thread")) != NULL )) {
202 NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n");
203 return NULL;
204 }
205 if (!NSK_JNI_VERIFY(jni,
206 (threadConstructor = NSK_CPP_STUB4(GetMethodID, jni, klass, "<init>", "(Ljava/lang/String;)V") ) != NULL )) {
207 NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n");
208 return NULL;
209 }
210
211 if (!NSK_JNI_VERIFY(jni,
212 (thread = NSK_CPP_STUB4(NewObject, jni, klass, threadConstructor, threadNameString)) != NULL ) ) {
213 NSK_COMPLAIN0("Failed to create Thread object\n");
214 return NULL;
215 }
216
217 if (!NSK_JNI_VERIFY(jni, (thread =
218 NSK_CPP_STUB2(NewGlobalRef, jni, thread)) != NULL)) {
219 NSK_COMPLAIN0("Failed to create global reference\n");
220 return NULL;
221 }
222
223 return thread;
224 }
225
226 // class redefinition
227
228 int nsk_jvmti_aod_redefineClass(
229 Options * options,
230 jvmtiEnv * jvmti,
231 jclass classToRedefine,
232 const char * fileName) {
233
234 if (!nsk_aod_optionSpecified(options, PATH_TO_NEW_BYTE_CODE_OPTION)) {
235 NSK_COMPLAIN1("Option '%s' isn't specified\n", PATH_TO_NEW_BYTE_CODE_OPTION);
236 return NSK_FALSE;
237 }
238 if (fileName == NULL) {
|
70 }
71
72 Options* nsk_jvmti_aod_getMultiagentsOptions(jvmtiEnv *jvmti) {
73 int i;
74 for (i = 0; i < multiagentsCount; i++) {
75 if (multiagentsOptions[i].jvmti == jvmti) {
76 return multiagentsOptions[i].options;
77 }
78 }
79
80 NSK_COMPLAIN1("Options for jvmtiEnv %p weren't found\n", jvmti);
81
82 return NULL;
83 }
84
85 /*
86 * Auxiliary functions
87 */
88
89 void nsk_jvmti_aod_deallocate(jvmtiEnv *jvmti, unsigned char* mem) {
90 if (!NSK_JVMTI_VERIFY(jvmti->Deallocate(mem))) {
91 NSK_COMPLAIN0("Deallocate failed\n");
92
93 /*
94 * if deallocate fails it isn't critical and test execution can continue without problems,
95 * just call nsk_aod_internal_error to inform framework about this error
96 */
97 nsk_aod_internal_error();
98 }
99 }
100
101 int nsk_jvmti_aod_getClassName(jvmtiEnv *jvmti, jclass klass, char classNameBuffer[]) {
102 char* className;
103
104 if (!NSK_JVMTI_VERIFY(jvmti->GetClassSignature(klass, &className, NULL))) {
105 NSK_COMPLAIN0("Failed to get class name\n");
106 classNameBuffer[0] = '\0';
107 return NSK_FALSE;
108 } else {
109 strcpy(classNameBuffer, className);
110
111 nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)className);
112
113 return NSK_TRUE;
114 }
115 }
116
117 int nsk_jvmti_aod_getThreadName(jvmtiEnv * jvmti, jthread thread, char threadNameBuffer[]) {
118 jvmtiThreadInfo info;
119 if (!NSK_JVMTI_VERIFY(jvmti->GetThreadInfo(thread, &info))){
120 NSK_COMPLAIN0("Failed to get thread info\n");
121 threadNameBuffer[0] = '\0';
122 return NSK_FALSE;
123 } else {
124 strcpy(threadNameBuffer, info.name);
125
126 nsk_jvmti_aod_deallocate(jvmti, (unsigned char*)info.name);
127
128 return NSK_TRUE;
129 }
130 }
131
132 // events enabling/disabling
133
134 int nsk_jvmti_aod_disableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) {
135 int i;
136 int status = NSK_TRUE;
137
138 for (i = 0; i < eventsNumber; i++) {
139 if (!nsk_jvmti_aod_disableEvent(jvmti, events[i])) {
144 return status;
145 }
146
147 int nsk_jvmti_aod_enableEvents(jvmtiEnv* jvmti, jvmtiEvent events[], int eventsNumber) {
148 int i;
149 for (i = 0; i < eventsNumber; i++) {
150 if (!nsk_jvmti_aod_enableEvent(jvmti, events[i]))
151 return NSK_FALSE;
152 }
153
154 return NSK_TRUE;
155 }
156
157 // java threads creation
158
159 jthread nsk_jvmti_aod_createThread(JNIEnv *jni) {
160 jclass klass ;
161 jmethodID threadConstructor;
162 jthread thread;
163
164 if (!NSK_JNI_VERIFY(jni, (klass = jni->FindClass("java/lang/Thread")) != NULL )) {
165 NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n");
166 return NULL;
167 }
168 if (!NSK_JNI_VERIFY(jni,
169 (threadConstructor = jni->GetMethodID(klass, "<init>", "()V") ) != NULL )) {
170 NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n");
171 return NULL;
172 }
173
174 if (!NSK_JNI_VERIFY (jni,
175 (thread = jni->NewObject(klass, threadConstructor, NULL)) != NULL ) ) {
176 NSK_COMPLAIN0("Failed to create Thread object\n");
177 return NULL;
178 }
179
180 if (!NSK_JNI_VERIFY(jni, (thread = jni->NewGlobalRef(thread)) != NULL)) {
181 NSK_COMPLAIN0("Failed to create global reference\n");
182 return NULL;
183 }
184
185 return thread;
186 }
187
188 jthread nsk_jvmti_aod_createThreadWithName(JNIEnv *jni, const char* threadName) {
189 jclass klass ;
190 jmethodID threadConstructor;
191 jthread thread;
192 jstring threadNameString;
193
194 if (!NSK_JNI_VERIFY(jni, (threadNameString = jni->NewStringUTF(threadName)) != NULL))
195 return NULL;
196
197 if (!NSK_JNI_VERIFY(jni, (klass = jni->FindClass("java/lang/Thread")) != NULL )) {
198 NSK_COMPLAIN0("Failed to get the java.lang.Thread class\n");
199 return NULL;
200 }
201 if (!NSK_JNI_VERIFY(jni,
202 (threadConstructor = jni->GetMethodID(klass, "<init>", "(Ljava/lang/String;)V") ) != NULL )) {
203 NSK_COMPLAIN0("Failed to get java.lang.Thread constructor\n");
204 return NULL;
205 }
206
207 if (!NSK_JNI_VERIFY(jni,
208 (thread = jni->NewObject(klass, threadConstructor, threadNameString)) != NULL ) ) {
209 NSK_COMPLAIN0("Failed to create Thread object\n");
210 return NULL;
211 }
212
213 if (!NSK_JNI_VERIFY(jni, (thread = jni->NewGlobalRef(thread)) != NULL)) {
214 NSK_COMPLAIN0("Failed to create global reference\n");
215 return NULL;
216 }
217
218 return thread;
219 }
220
221 // class redefinition
222
223 int nsk_jvmti_aod_redefineClass(
224 Options * options,
225 jvmtiEnv * jvmti,
226 jclass classToRedefine,
227 const char * fileName) {
228
229 if (!nsk_aod_optionSpecified(options, PATH_TO_NEW_BYTE_CODE_OPTION)) {
230 NSK_COMPLAIN1("Option '%s' isn't specified\n", PATH_TO_NEW_BYTE_CODE_OPTION);
231 return NSK_FALSE;
232 }
233 if (fileName == NULL) {
|