< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

1346   // we had a privileged system domain
1347   if (local_array->is_empty()) {
1348     if (is_privileged && privileged_context.is_null()) return NULL;
1349 
1350     oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
1351     return JNIHandles::make_local(THREAD, result);
1352   }
1353 
1354   objArrayOop context = oopFactory::new_objArray(vmClasses::ProtectionDomain_klass(),
1355                                                  local_array->length(), CHECK_NULL);
1356   objArrayHandle h_context(thread, context);
1357   for (int index = 0; index < local_array->length(); index++) {
1358     h_context->obj_at_put(index, local_array->at(index)());
1359   }
1360 
1361   oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
1362 
1363   return JNIHandles::make_local(THREAD, result);
1364 JVM_END
1365 


















































1366 
1367 JVM_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
1368   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1369   return (k != NULL) && k->is_array_klass() ? true : false;
1370 JVM_END
1371 
1372 
1373 JVM_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
1374   oop mirror = JNIHandles::resolve_non_null(cls);
1375   return (jboolean) java_lang_Class::is_primitive(mirror);
1376 JVM_END
1377 
1378 
1379 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
1380   oop mirror = JNIHandles::resolve_non_null(cls);
1381   if (java_lang_Class::is_primitive(mirror)) {
1382     // Primitive type
1383     return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
1384   }
1385 

3097   if (JvmtiExport::should_post_data_dump()) {
3098     JvmtiExport::post_data_dump();
3099   }
3100 JVM_END
3101 
3102 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3103   // We don't use a ThreadsListHandle here because the current thread
3104   // must be alive.
3105   oop java_thread = JNIHandles::resolve_non_null(jthread);
3106   JavaThread* thr = java_lang_Thread::thread(java_thread);
3107   if (thread == thr && !thr->has_attached_via_jni()) {
3108     // Thread naming is only supported for the current thread and
3109     // we don't set the name of an attached thread to avoid stepping
3110     // on other programs.
3111     ResourceMark rm(thread);
3112     const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3113     os::set_native_thread_name(thread_name);
3114   }
3115 JVM_END
3116 
3117 JVM_ENTRY(jobject, JVM_ExtentLocalCache(JNIEnv* env, jclass threadClass))
3118   oop theCache = thread->extentLocalCache();
3119   if (theCache) {
3120     arrayOop objs = arrayOop(theCache);
3121     assert(objs->length() == ExtentLocalCacheSize * 2, "wrong length");
3122   }
3123   return JNIHandles::make_local(THREAD, theCache);
3124 JVM_END
3125 
3126 JVM_ENTRY(void, JVM_SetExtentLocalCache(JNIEnv* env, jclass threadClass,
3127                                        jobject theCache))
3128   arrayOop objs = arrayOop(JNIHandles::resolve(theCache));
3129   if (objs != NULL) {
3130     assert(objs->length() == ExtentLocalCacheSize * 2, "wrong length");
3131   }
3132   thread->set_extentLocalCache(objs);
3133 JVM_END
3134 
3135 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
3136 
3137 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
3138   ResourceMark rm(THREAD);
3139   JvmtiVMObjectAllocEventCollector oam;
3140   vframeStream vfst(thread);
3141 
3142   if (vmClasses::reflect_CallerSensitive_klass() != NULL) {
3143     // This must only be called from SecurityManager.getClassContext
3144     Method* m = vfst.method();
3145     if (!(m->method_holder() == vmClasses::SecurityManager_klass() &&
3146           m->name()          == vmSymbols::getClassContext_name() &&
3147           m->signature()     == vmSymbols::void_class_array_signature())) {
3148       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext");
3149     }
3150   }
3151 
3152   // Collect method holders

4002 JVM_END
4003 
4004 /*
4005  * Return the current class's class file version.  The low order 16 bits of the
4006  * returned jint contain the class's major version.  The high order 16 bits
4007  * contain the class's minor version.
4008  */
4009 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4010   oop mirror = JNIHandles::resolve_non_null(current);
4011   if (java_lang_Class::is_primitive(mirror)) {
4012     // return latest major version and minor version of 0.
4013     return JVM_CLASSFILE_MAJOR_VERSION;
4014   }
4015   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4016 
4017   Klass* c = java_lang_Class::as_Klass(mirror);
4018   assert(c->is_instance_klass(), "must be");
4019   InstanceKlass* ik = InstanceKlass::cast(c);
4020   return (ik->minor_version() << 16) | ik->major_version();
4021 JVM_END










1346   // we had a privileged system domain
1347   if (local_array->is_empty()) {
1348     if (is_privileged && privileged_context.is_null()) return NULL;
1349 
1350     oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
1351     return JNIHandles::make_local(THREAD, result);
1352   }
1353 
1354   objArrayOop context = oopFactory::new_objArray(vmClasses::ProtectionDomain_klass(),
1355                                                  local_array->length(), CHECK_NULL);
1356   objArrayHandle h_context(thread, context);
1357   for (int index = 0; index < local_array->length(); index++) {
1358     h_context->obj_at_put(index, local_array->at(index)());
1359   }
1360 
1361   oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
1362 
1363   return JNIHandles::make_local(THREAD, result);
1364 JVM_END
1365 
1366 class ScopedValueBindingsResolver {
1367 public:
1368   InstanceKlass* Carrier_klass;
1369   ScopedValueBindingsResolver(JavaThread* THREAD) {
1370     Klass *k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_incubator_concurrent_ScopedValue_Carrier(), true, THREAD);
1371     Carrier_klass = InstanceKlass::cast(k);
1372   }
1373 };
1374 
1375 JVM_ENTRY(jobject, JVM_FindScopedValueBindings(JNIEnv *env, jclass cls))
1376   ResourceMark rm(THREAD);
1377   GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1378   JvmtiVMObjectAllocEventCollector oam;
1379 
1380   bool found = false;
1381 
1382   static ScopedValueBindingsResolver resolver(THREAD);
1383 
1384   // Iterate through Java frames
1385   vframeStream vfst(thread);
1386   for(; !vfst.at_end(); vfst.next()) {
1387     int loc = 0;
1388     // get method of frame
1389     Method* method = vfst.method();
1390 
1391     Symbol *name = method->name();
1392 
1393     InstanceKlass* holder = method->method_holder();
1394     if (name == vmSymbols::runWith_method_name()) {
1395       if ((holder == resolver.Carrier_klass
1396            || holder == vmClasses::VirtualThread_klass()
1397            || holder == vmClasses::Thread_klass())) {
1398         loc = 1;
1399       }
1400     }
1401 
1402     if (loc != 0) {
1403       javaVFrame *frame = vfst.asJavaVFrame();
1404       StackValueCollection* locals = frame->locals();
1405       StackValue* head_sv = locals->at(loc); // jdk/incubator/concurrent/ScopedValue$Snapshot
1406       Handle result = head_sv->get_obj();
1407       assert(!head_sv->obj_is_scalar_replaced(), "found scalar-replaced object");
1408       if (result() != NULL) {
1409         return JNIHandles::make_local(THREAD, result());
1410       }
1411     }
1412   }
1413 
1414   return NULL;
1415 JVM_END
1416 
1417 JVM_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
1418   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1419   return (k != NULL) && k->is_array_klass() ? true : false;
1420 JVM_END
1421 
1422 
1423 JVM_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
1424   oop mirror = JNIHandles::resolve_non_null(cls);
1425   return (jboolean) java_lang_Class::is_primitive(mirror);
1426 JVM_END
1427 
1428 
1429 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
1430   oop mirror = JNIHandles::resolve_non_null(cls);
1431   if (java_lang_Class::is_primitive(mirror)) {
1432     // Primitive type
1433     return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
1434   }
1435 

3147   if (JvmtiExport::should_post_data_dump()) {
3148     JvmtiExport::post_data_dump();
3149   }
3150 JVM_END
3151 
3152 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3153   // We don't use a ThreadsListHandle here because the current thread
3154   // must be alive.
3155   oop java_thread = JNIHandles::resolve_non_null(jthread);
3156   JavaThread* thr = java_lang_Thread::thread(java_thread);
3157   if (thread == thr && !thr->has_attached_via_jni()) {
3158     // Thread naming is only supported for the current thread and
3159     // we don't set the name of an attached thread to avoid stepping
3160     // on other programs.
3161     ResourceMark rm(thread);
3162     const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3163     os::set_native_thread_name(thread_name);
3164   }
3165 JVM_END
3166 
3167 JVM_ENTRY(jobject, JVM_ScopedValueCache(JNIEnv* env, jclass threadClass))
3168   oop theCache = thread->scopedValueCache();




3169   return JNIHandles::make_local(THREAD, theCache);
3170 JVM_END
3171 
3172 JVM_ENTRY(void, JVM_SetScopedValueCache(JNIEnv* env, jclass threadClass,
3173                                        jobject theCache))
3174   arrayOop objs = arrayOop(JNIHandles::resolve(theCache));
3175   thread->set_scopedValueCache(objs);



3176 JVM_END
3177 
3178 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
3179 
3180 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
3181   ResourceMark rm(THREAD);
3182   JvmtiVMObjectAllocEventCollector oam;
3183   vframeStream vfst(thread);
3184 
3185   if (vmClasses::reflect_CallerSensitive_klass() != NULL) {
3186     // This must only be called from SecurityManager.getClassContext
3187     Method* m = vfst.method();
3188     if (!(m->method_holder() == vmClasses::SecurityManager_klass() &&
3189           m->name()          == vmSymbols::getClassContext_name() &&
3190           m->signature()     == vmSymbols::void_class_array_signature())) {
3191       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext");
3192     }
3193   }
3194 
3195   // Collect method holders

4045 JVM_END
4046 
4047 /*
4048  * Return the current class's class file version.  The low order 16 bits of the
4049  * returned jint contain the class's major version.  The high order 16 bits
4050  * contain the class's minor version.
4051  */
4052 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4053   oop mirror = JNIHandles::resolve_non_null(current);
4054   if (java_lang_Class::is_primitive(mirror)) {
4055     // return latest major version and minor version of 0.
4056     return JVM_CLASSFILE_MAJOR_VERSION;
4057   }
4058   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4059 
4060   Klass* c = java_lang_Class::as_Klass(mirror);
4061   assert(c->is_instance_klass(), "must be");
4062   InstanceKlass* ik = InstanceKlass::cast(c);
4063   return (ik->minor_version() << 16) | ik->major_version();
4064 JVM_END
4065 
4066 /*
4067  * Ensure that code doing a stackwalk and using javaVFrame::locals() to
4068  * get the value will see a materialized value and not a scalar-replaced
4069  * null value.
4070  */
4071 JVM_ENTRY(void, JVM_EnsureMaterializedForStackWalk_func(JNIEnv* env, jobject vthread, jobject value))
4072   JVM_EnsureMaterializedForStackWalk(env, value);
4073 JVM_END
< prev index next >