< prev index next >

src/hotspot/share/prims/unsafe.cpp

Print this page

336 
337 DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean)
338 DEFINE_GETSETOOP_VOLATILE(jbyte, Byte)
339 DEFINE_GETSETOOP_VOLATILE(jshort, Short);
340 DEFINE_GETSETOOP_VOLATILE(jchar, Char);
341 DEFINE_GETSETOOP_VOLATILE(jint, Int);
342 DEFINE_GETSETOOP_VOLATILE(jlong, Long);
343 DEFINE_GETSETOOP_VOLATILE(jfloat, Float);
344 DEFINE_GETSETOOP_VOLATILE(jdouble, Double);
345 
346 #undef DEFINE_GETSETOOP_VOLATILE
347 
348 UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
349   OrderAccess::fence();
350 } UNSAFE_END
351 
352 ////// Allocation requests
353 
354 UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
355   JvmtiVMObjectAllocEventCollector oam;
356   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(cls), CHECK_NULL);
357   return JNIHandles::make_local(THREAD, i);
358 } UNSAFE_END
359 
360 UNSAFE_LEAF(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {
361   size_t sz = (size_t)size;
362 
363   assert(is_aligned(sz, HeapWordSize), "sz not aligned");
364 
365   void* x = os::malloc(sz, mtOther);
366 
367   return addr_to_java(x);
368 } UNSAFE_END
369 
370 UNSAFE_LEAF(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) {
371   void* p = addr_from_java(addr);
372   size_t sz = (size_t)size;
373 
374   assert(is_aligned(sz, HeapWordSize), "sz not aligned");
375 
376   void* x = os::realloc(p, sz, mtOther);

542   // the address would operate alone, without any base pointer.
543 
544   oop reflected   = JNIHandles::resolve_non_null(field);
545   oop mirror      = java_lang_reflect_Field::clazz(reflected);
546   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
547 
548   if ((modifiers & JVM_ACC_STATIC) == 0) {
549     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
550   }
551 
552   return JNIHandles::make_local(THREAD, mirror);
553 } UNSAFE_END
554 
555 UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) {
556   assert(clazz != nullptr, "clazz must not be null");
557 
558   oop mirror = JNIHandles::resolve_non_null(clazz);
559 
560   Klass* klass = java_lang_Class::as_Klass(mirror);
561   if (klass != nullptr && klass->should_be_initialized()) {





562     InstanceKlass* k = InstanceKlass::cast(klass);
563     k->initialize(CHECK);
564   }
565 }
566 UNSAFE_END
567 
568 UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) {
569   assert(clazz != nullptr, "clazz must not be null");
570 
571   oop mirror = JNIHandles::resolve_non_null(clazz);
572   Klass* klass = java_lang_Class::as_Klass(mirror);
573 
574   if (klass != nullptr && klass->should_be_initialized()) {
575     return true;
576   }
577 
578   return false;
579 }
580 UNSAFE_END
581 

336 
337 DEFINE_GETSETOOP_VOLATILE(jboolean, Boolean)
338 DEFINE_GETSETOOP_VOLATILE(jbyte, Byte)
339 DEFINE_GETSETOOP_VOLATILE(jshort, Short);
340 DEFINE_GETSETOOP_VOLATILE(jchar, Char);
341 DEFINE_GETSETOOP_VOLATILE(jint, Int);
342 DEFINE_GETSETOOP_VOLATILE(jlong, Long);
343 DEFINE_GETSETOOP_VOLATILE(jfloat, Float);
344 DEFINE_GETSETOOP_VOLATILE(jdouble, Double);
345 
346 #undef DEFINE_GETSETOOP_VOLATILE
347 
348 UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
349   OrderAccess::fence();
350 } UNSAFE_END
351 
352 ////// Allocation requests
353 
354 UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
355   JvmtiVMObjectAllocEventCollector oam;
356   instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(cls), "unsafe", CHECK_NULL);
357   return JNIHandles::make_local(THREAD, i);
358 } UNSAFE_END
359 
360 UNSAFE_LEAF(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {
361   size_t sz = (size_t)size;
362 
363   assert(is_aligned(sz, HeapWordSize), "sz not aligned");
364 
365   void* x = os::malloc(sz, mtOther);
366 
367   return addr_to_java(x);
368 } UNSAFE_END
369 
370 UNSAFE_LEAF(jlong, Unsafe_ReallocateMemory0(JNIEnv *env, jobject unsafe, jlong addr, jlong size)) {
371   void* p = addr_from_java(addr);
372   size_t sz = (size_t)size;
373 
374   assert(is_aligned(sz, HeapWordSize), "sz not aligned");
375 
376   void* x = os::realloc(p, sz, mtOther);

542   // the address would operate alone, without any base pointer.
543 
544   oop reflected   = JNIHandles::resolve_non_null(field);
545   oop mirror      = java_lang_reflect_Field::clazz(reflected);
546   int modifiers   = java_lang_reflect_Field::modifiers(reflected);
547 
548   if ((modifiers & JVM_ACC_STATIC) == 0) {
549     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
550   }
551 
552   return JNIHandles::make_local(THREAD, mirror);
553 } UNSAFE_END
554 
555 UNSAFE_ENTRY(void, Unsafe_EnsureClassInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) {
556   assert(clazz != nullptr, "clazz must not be null");
557 
558   oop mirror = JNIHandles::resolve_non_null(clazz);
559 
560   Klass* klass = java_lang_Class::as_Klass(mirror);
561   if (klass != nullptr && klass->should_be_initialized()) {
562     if (RecordTraining) {
563       InstanceKlass* k = InstanceKlass::cast(klass);
564       k->record_initialization_touch("ensure", nullptr, nullptr, nullptr,
565                                      "unsafe", CHECK);
566     }
567     InstanceKlass* k = InstanceKlass::cast(klass);
568     k->initialize(CHECK);
569   }
570 }
571 UNSAFE_END
572 
573 UNSAFE_ENTRY(jboolean, Unsafe_ShouldBeInitialized0(JNIEnv *env, jobject unsafe, jobject clazz)) {
574   assert(clazz != nullptr, "clazz must not be null");
575 
576   oop mirror = JNIHandles::resolve_non_null(clazz);
577   Klass* klass = java_lang_Class::as_Klass(mirror);
578 
579   if (klass != nullptr && klass->should_be_initialized()) {
580     return true;
581   }
582 
583   return false;
584 }
585 UNSAFE_END
586 
< prev index next >