hotspot/src/share/vm/prims/unsafe.cpp
changeset 46329 53ccc37bda19
parent 41181 2ce2f1c582ca
child 46458 3c12af929e7d
equal deleted inserted replaced
46328:6061df52d610 46329:53ccc37bda19
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   843 // various kinds of metaobjects must be introduced as constants into bytecode.
   843 // various kinds of metaobjects must be introduced as constants into bytecode.
   844 // Note the cast (Object), which tells the verifier to expect an arbitrary object,
   844 // Note the cast (Object), which tells the verifier to expect an arbitrary object,
   845 // not just a literal string.  For such ldc instructions, the verifier uses the
   845 // not just a literal string.  For such ldc instructions, the verifier uses the
   846 // type Object instead of String, if the loaded constant is not in fact a String.
   846 // type Object instead of String, if the loaded constant is not in fact a String.
   847 
   847 
   848 static instanceKlassHandle
   848 static InstanceKlass*
   849 Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
   849 Unsafe_DefineAnonymousClass_impl(JNIEnv *env,
   850                                  jclass host_class, jbyteArray data, jobjectArray cp_patches_jh,
   850                                  jclass host_class, jbyteArray data, jobjectArray cp_patches_jh,
   851                                  u1** temp_alloc,
   851                                  u1** temp_alloc,
   852                                  TRAPS) {
   852                                  TRAPS) {
   853   assert(host_class != NULL, "host_class must not be NULL");
   853   assert(host_class != NULL, "host_class must not be NULL");
   930                                                 CHECK_NULL);
   930                                                 CHECK_NULL);
   931   if (anonk == NULL) {
   931   if (anonk == NULL) {
   932     return NULL;
   932     return NULL;
   933   }
   933   }
   934 
   934 
   935   return instanceKlassHandle(THREAD, anonk);
   935   return InstanceKlass::cast(anonk);
   936 }
   936 }
   937 
   937 
   938 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) {
   938 UNSAFE_ENTRY(jclass, Unsafe_DefineAnonymousClass0(JNIEnv *env, jobject unsafe, jclass host_class, jbyteArray data, jobjectArray cp_patches_jh)) {
   939   ResourceMark rm(THREAD);
   939   ResourceMark rm(THREAD);
   940 
   940 
   941   instanceKlassHandle anon_klass;
       
   942   jobject res_jh = NULL;
   941   jobject res_jh = NULL;
   943   u1* temp_alloc = NULL;
   942   u1* temp_alloc = NULL;
   944 
   943 
   945   anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD);
   944   InstanceKlass* anon_klass = Unsafe_DefineAnonymousClass_impl(env, host_class, data, cp_patches_jh, &temp_alloc, THREAD);
   946   if (anon_klass() != NULL) {
   945   if (anon_klass != NULL) {
   947     res_jh = JNIHandles::make_local(env, anon_klass->java_mirror());
   946     res_jh = JNIHandles::make_local(env, anon_klass->java_mirror());
   948   }
   947   }
   949 
   948 
   950   // try/finally clause:
   949   // try/finally clause:
   951   if (temp_alloc != NULL) {
   950   if (temp_alloc != NULL) {
   953   }
   952   }
   954 
   953 
   955   // The anonymous class loader data has been artificially been kept alive to
   954   // The anonymous class loader data has been artificially been kept alive to
   956   // this point.   The mirror and any instances of this class have to keep
   955   // this point.   The mirror and any instances of this class have to keep
   957   // it alive afterwards.
   956   // it alive afterwards.
   958   if (anon_klass() != NULL) {
   957   if (anon_klass != NULL) {
   959     anon_klass->class_loader_data()->dec_keep_alive();
   958     anon_klass->class_loader_data()->dec_keep_alive();
   960   }
   959   }
   961 
   960 
   962   // let caller initialize it as needed...
   961   // let caller initialize it as needed...
   963 
   962