7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderExt.hpp"
27 #include "classfile/modules.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "interpreter/bytecodeStream.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "jvmtifiles/jvmtiEnv.hpp"
33 #include "logging/log.hpp"
34 #include "logging/logConfiguration.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "memory/universe.inline.hpp"
37 #include "oops/instanceKlass.hpp"
38 #include "oops/objArrayOop.inline.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "prims/jniCheck.hpp"
41 #include "prims/jvm_misc.hpp"
42 #include "prims/jvmtiAgentThread.hpp"
43 #include "prims/jvmtiClassFileReconstituter.hpp"
44 #include "prims/jvmtiCodeBlobEvents.hpp"
45 #include "prims/jvmtiExtensions.hpp"
46 #include "prims/jvmtiGetLoadedClasses.hpp"
207 // module_ptr - pre-checked for NULL
208 jvmtiError
209 JvmtiEnv::GetNamedModule(jobject class_loader, const char* package_name, jobject* module_ptr) {
210 JavaThread* THREAD = JavaThread::current(); // pass to macros
211 ResourceMark rm(THREAD);
212
213 Handle h_loader (THREAD, JNIHandles::resolve(class_loader));
214 // Check that loader is a subclass of java.lang.ClassLoader.
215 if (h_loader.not_null() && !java_lang_ClassLoader::is_subclass(h_loader->klass())) {
216 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
217 }
218 jobject module = Modules::get_named_module(h_loader, package_name, THREAD);
219 if (HAS_PENDING_EXCEPTION) {
220 CLEAR_PENDING_EXCEPTION;
221 return JVMTI_ERROR_INTERNAL; // unexpected exception
222 }
223 *module_ptr = module;
224 return JVMTI_ERROR_NONE;
225 } /* end GetNamedModule */
226
227 //
228 // Class functions
229 //
230
231 // class_count_ptr - pre-checked for NULL
232 // classes_ptr - pre-checked for NULL
233 jvmtiError
234 JvmtiEnv::GetLoadedClasses(jint* class_count_ptr, jclass** classes_ptr) {
235 return JvmtiGetLoadedClasses::getLoadedClasses(this, class_count_ptr, classes_ptr);
236 } /* end GetLoadedClasses */
237
238
239 // initiating_loader - NULL is a valid value, must be checked
240 // class_count_ptr - pre-checked for NULL
241 // classes_ptr - pre-checked for NULL
242 jvmtiError
243 JvmtiEnv::GetClassLoaderClasses(jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) {
244 return JvmtiGetLoadedClasses::getClassLoaderClasses(this, initiating_loader,
245 class_count_ptr, classes_ptr);
246 } /* end GetClassLoaderClasses */
3448 } /* end GetTime */
3449
3450
3451 // processor_count_ptr - pre-checked for NULL
3452 jvmtiError
3453 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3454 *processor_count_ptr = os::active_processor_count();
3455 return JVMTI_ERROR_NONE;
3456 } /* end GetAvailableProcessors */
3457
3458 //
3459 // System Properties functions
3460 //
3461
3462 // count_ptr - pre-checked for NULL
3463 // property_ptr - pre-checked for NULL
3464 jvmtiError
3465 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3466 jvmtiError err = JVMTI_ERROR_NONE;
3467
3468 *count_ptr = Arguments::PropertyList_count(Arguments::system_properties());
3469
3470 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3471 if (err != JVMTI_ERROR_NONE) {
3472 return err;
3473 }
3474 int i = 0 ;
3475 for (SystemProperty* p = Arguments::system_properties(); p != NULL && i < *count_ptr; p = p->next(), i++) {
3476 const char *key = p->key();
3477 char **tmp_value = *property_ptr+i;
3478 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value);
3479 if (err == JVMTI_ERROR_NONE) {
3480 strcpy(*tmp_value, key);
3481 } else {
3482 // clean up previously allocated memory.
3483 for (int j=0; j<i; j++) {
3484 Deallocate((unsigned char*)*property_ptr+j);
3485 }
3486 Deallocate((unsigned char*)property_ptr);
3487 break;
3488 }
3489 }
3490 return err;
3491 } /* end GetSystemProperties */
3492
3493
3494 // property - pre-checked for NULL
3495 // value_ptr - pre-checked for NULL
3496 jvmtiError
3497 JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) {
3498 jvmtiError err = JVMTI_ERROR_NONE;
3499 const char *value;
3500
3501 value = Arguments::PropertyList_get_value(Arguments::system_properties(), property);
3502 if (value == NULL) {
3503 err = JVMTI_ERROR_NOT_AVAILABLE;
3504 } else {
3505 err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr);
3506 if (err == JVMTI_ERROR_NONE) {
3507 strcpy(*value_ptr, value);
3508 }
3509 }
3510 return err;
3511 } /* end GetSystemProperty */
3512
3513
3514 // property - pre-checked for NULL
3515 // value - NULL is a valid value, must be checked
3516 jvmtiError
3517 JvmtiEnv::SetSystemProperty(const char* property, const char* value_ptr) {
3518 jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE;
3519
3520 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
3521 if (strcmp(property, p->key()) == 0) {
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoaderExt.hpp"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "classfile/stringTable.hpp"
29 #include "classfile/modules.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "interpreter/bytecodeStream.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "jvmtifiles/jvmtiEnv.hpp"
35 #include "logging/log.hpp"
36 #include "logging/logConfiguration.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.inline.hpp"
39 #include "oops/instanceKlass.hpp"
40 #include "oops/objArrayOop.inline.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "prims/jniCheck.hpp"
43 #include "prims/jvm_misc.hpp"
44 #include "prims/jvmtiAgentThread.hpp"
45 #include "prims/jvmtiClassFileReconstituter.hpp"
46 #include "prims/jvmtiCodeBlobEvents.hpp"
47 #include "prims/jvmtiExtensions.hpp"
48 #include "prims/jvmtiGetLoadedClasses.hpp"
209 // module_ptr - pre-checked for NULL
210 jvmtiError
211 JvmtiEnv::GetNamedModule(jobject class_loader, const char* package_name, jobject* module_ptr) {
212 JavaThread* THREAD = JavaThread::current(); // pass to macros
213 ResourceMark rm(THREAD);
214
215 Handle h_loader (THREAD, JNIHandles::resolve(class_loader));
216 // Check that loader is a subclass of java.lang.ClassLoader.
217 if (h_loader.not_null() && !java_lang_ClassLoader::is_subclass(h_loader->klass())) {
218 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
219 }
220 jobject module = Modules::get_named_module(h_loader, package_name, THREAD);
221 if (HAS_PENDING_EXCEPTION) {
222 CLEAR_PENDING_EXCEPTION;
223 return JVMTI_ERROR_INTERNAL; // unexpected exception
224 }
225 *module_ptr = module;
226 return JVMTI_ERROR_NONE;
227 } /* end GetNamedModule */
228
229
230 //
231 // Class functions
232 //
233
234 // class_count_ptr - pre-checked for NULL
235 // classes_ptr - pre-checked for NULL
236 jvmtiError
237 JvmtiEnv::GetLoadedClasses(jint* class_count_ptr, jclass** classes_ptr) {
238 return JvmtiGetLoadedClasses::getLoadedClasses(this, class_count_ptr, classes_ptr);
239 } /* end GetLoadedClasses */
240
241
242 // initiating_loader - NULL is a valid value, must be checked
243 // class_count_ptr - pre-checked for NULL
244 // classes_ptr - pre-checked for NULL
245 jvmtiError
246 JvmtiEnv::GetClassLoaderClasses(jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) {
247 return JvmtiGetLoadedClasses::getClassLoaderClasses(this, initiating_loader,
248 class_count_ptr, classes_ptr);
249 } /* end GetClassLoaderClasses */
3451 } /* end GetTime */
3452
3453
3454 // processor_count_ptr - pre-checked for NULL
3455 jvmtiError
3456 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3457 *processor_count_ptr = os::active_processor_count();
3458 return JVMTI_ERROR_NONE;
3459 } /* end GetAvailableProcessors */
3460
3461 //
3462 // System Properties functions
3463 //
3464
3465 // count_ptr - pre-checked for NULL
3466 // property_ptr - pre-checked for NULL
3467 jvmtiError
3468 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3469 jvmtiError err = JVMTI_ERROR_NONE;
3470
3471 // Get the number of readable properties.
3472 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3473
3474 // Allocate memory to hold the exact number of readable properties.
3475 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3476 if (err != JVMTI_ERROR_NONE) {
3477 return err;
3478 }
3479 int readable_count = 0;
3480 // Loop through the system properties until all the readable properties are found.
3481 for (SystemProperty* p = Arguments::system_properties(); p != NULL && readable_count < *count_ptr; p = p->next()) {
3482 if (p->is_readable()) {
3483 const char *key = p->key();
3484 char **tmp_value = *property_ptr+readable_count++;
3485 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value);
3486 if (err == JVMTI_ERROR_NONE) {
3487 strcpy(*tmp_value, key);
3488 } else {
3489 // clean up previously allocated memory.
3490 for (int j=0; j<readable_count; j++) {
3491 Deallocate((unsigned char*)*property_ptr+j);
3492 }
3493 Deallocate((unsigned char*)property_ptr);
3494 break;
3495 }
3496 }
3497 }
3498 assert(err != JVMTI_ERROR_NONE || readable_count == *count_ptr, "Bad readable property count");
3499 return err;
3500 } /* end GetSystemProperties */
3501
3502
3503 // property - pre-checked for NULL
3504 // value_ptr - pre-checked for NULL
3505 jvmtiError
3506 JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) {
3507 jvmtiError err = JVMTI_ERROR_NONE;
3508 const char *value;
3509
3510 // Return JVMTI_ERROR_NOT_AVAILABLE if property is not readable or doesn't exist.
3511 value = Arguments::PropertyList_get_readable_value(Arguments::system_properties(), property);
3512 if (value == NULL) {
3513 err = JVMTI_ERROR_NOT_AVAILABLE;
3514 } else {
3515 err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr);
3516 if (err == JVMTI_ERROR_NONE) {
3517 strcpy(*value_ptr, value);
3518 }
3519 }
3520 return err;
3521 } /* end GetSystemProperty */
3522
3523
3524 // property - pre-checked for NULL
3525 // value - NULL is a valid value, must be checked
3526 jvmtiError
3527 JvmtiEnv::SetSystemProperty(const char* property, const char* value_ptr) {
3528 jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE;
3529
3530 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
3531 if (strcmp(property, p->key()) == 0) {
|