hotspot/src/share/vm/prims/unsafe.cpp
changeset 14588 8ec26d2d9339
parent 14488 ab48109f7d1b
child 14832 61b025224ac9
equal deleted inserted replaced
14584:bd4290e6d0a5 14588:8ec26d2d9339
   994 // various kinds of metaobjects must be introduced as constants into bytecode.
   994 // various kinds of metaobjects must be introduced as constants into bytecode.
   995 // Note the cast (Object), which tells the verifier to expect an arbitrary object,
   995 // Note the cast (Object), which tells the verifier to expect an arbitrary object,
   996 // not just a literal string.  For such ldc instructions, the verifier uses the
   996 // not just a literal string.  For such ldc instructions, the verifier uses the
   997 // type Object instead of String, if the loaded constant is not in fact a String.
   997 // type Object instead of String, if the loaded constant is not in fact a String.
   998 
   998 
   999 static oop
   999 static instanceKlassHandle
  1000 Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
  1000 Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
  1001                                  jclass host_class, jbyteArray data, jobjectArray cp_patches_jh,
  1001                                  jclass host_class, jbyteArray data, jobjectArray cp_patches_jh,
  1002                                  HeapWord* *temp_alloc,
  1002                                  HeapWord* *temp_alloc,
  1003                                  TRAPS) {
  1003                                  TRAPS) {
  1004 
  1004 
  1071                                                     CHECK_NULL);
  1071                                                     CHECK_NULL);
  1072     if (anonk == NULL)  return NULL;
  1072     if (anonk == NULL)  return NULL;
  1073     anon_klass = instanceKlassHandle(THREAD, anonk);
  1073     anon_klass = instanceKlassHandle(THREAD, anonk);
  1074   }
  1074   }
  1075 
  1075 
  1076   // let caller initialize it as needed...
  1076   return anon_klass;
  1077 
       
  1078   return anon_klass->java_mirror();
       
  1079 }
  1077 }
  1080 
  1078 
  1081 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh))
  1079 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh))
  1082 {
  1080 {
       
  1081   instanceKlassHandle anon_klass;
       
  1082   jobject res_jh = NULL;
       
  1083 
  1083   UnsafeWrapper("Unsafe_DefineAnonymousClass");
  1084   UnsafeWrapper("Unsafe_DefineAnonymousClass");
  1084   ResourceMark rm(THREAD);
  1085   ResourceMark rm(THREAD);
  1085 
  1086 
  1086   HeapWord* temp_alloc = NULL;
  1087   HeapWord* temp_alloc = NULL;
  1087 
  1088 
  1088   jobject res_jh = NULL;
  1089   anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data,
  1089 
  1090                                                 cp_patches_jh,
  1090   { oop res_oop = Unsafe_DefineAnonymousClass_impl(env,
       
  1091                                                    host_class, data, cp_patches_jh,
       
  1092                                                    &temp_alloc, THREAD);
  1091                                                    &temp_alloc, THREAD);
  1093     if (res_oop != NULL)
  1092   if (anon_klass() != NULL)
  1094       res_jh = JNIHandles::make_local(env, res_oop);
  1093     res_jh = JNIHandles::make_local(env, anon_klass->java_mirror());
  1095   }
       
  1096 
  1094 
  1097   // try/finally clause:
  1095   // try/finally clause:
  1098   if (temp_alloc != NULL) {
  1096   if (temp_alloc != NULL) {
  1099     FREE_C_HEAP_ARRAY(HeapWord, temp_alloc, mtInternal);
  1097     FREE_C_HEAP_ARRAY(HeapWord, temp_alloc, mtInternal);
  1100   }
  1098   }
       
  1099 
       
  1100   // The anonymous class loader data has been artificially been kept alive to
       
  1101   // this point.   The mirror and any instances of this class have to keep
       
  1102   // it alive afterwards.
       
  1103   if (anon_klass() != NULL) {
       
  1104     anon_klass->class_loader_data()->set_keep_alive(false);
       
  1105   }
       
  1106 
       
  1107   // let caller initialize it as needed...
  1101 
  1108 
  1102   return (jclass) res_jh;
  1109   return (jclass) res_jh;
  1103 }
  1110 }
  1104 UNSAFE_END
  1111 UNSAFE_END
  1105 
  1112