< prev index next >

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Print this page

1588         if (vf->is_compiled_frame()) {
1589           // compiled method frame
1590           compiledVFrame* cvf = compiledVFrame::cast(vf);
1591 
1592           ScopeDesc* scope = cvf->scope();
1593           // native wrappers do not have a scope
1594           if (scope != nullptr && scope->objects() != nullptr) {
1595             prev_cvf = cvf;
1596 
1597             GrowableArray<ScopeValue*>* objects = nullptr;
1598             if (!realloc_called) {
1599               objects = scope->objects();
1600             } else {
1601               // some object might already have been re-allocated, only reallocate the non-allocated ones
1602               objects = get_unallocated_objects_or_null(scope->objects());
1603             }
1604 
1605             if (objects != nullptr) {
1606               RegisterMap reg_map(vf->register_map());
1607               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1608               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1609               realloc_called = true;
1610             }
1611 
1612             GrowableArray<ScopeValue*>* local_values = scope->locals();
1613             for (int i = 0; i < local_values->length(); i++) {
1614               ScopeValue* value = local_values->at(i);
1615               assert(!value->is_object_merge(), "Should not be.");
1616               if (value->is_object()) {
1617                 if (localIsVirtual_h.is_null()) {
1618                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1619                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1620                 }
1621                 localIsVirtual_h->bool_at_put(i, true);
1622               }
1623             }
1624           }
1625 
1626           locals = cvf->locals();
1627           frame_number = cvf->vframe_id();
1628         } else {

1839       break;
1840     }
1841     vf = vf->sender();
1842   }
1843 
1844   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1845   if (last_frame_number >= virtualFrames->length()) {
1846     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1847   }
1848 
1849   // Reallocate the non-escaping objects and restore their fields.
1850   assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1851   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1852 
1853   if (objects == nullptr) {
1854     // no objects to materialize
1855     return;
1856   }
1857 
1858   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1859   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1860 
1861   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1862     compiledVFrame* cvf = virtualFrames->at(frame_index);
1863 
1864     GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1865     StackValueCollection* locals = cvf->locals();
1866     if (locals != nullptr) {
1867       for (int i2 = 0; i2 < locals->size(); i2++) {
1868         StackValue* var = locals->at(i2);
1869         assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1870         if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1871           jvalue val;
1872           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1873           cvf->update_local(T_OBJECT, i2, val);
1874         }
1875       }
1876     }
1877 
1878     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1879     StackValueCollection* expressions = cvf->expressions();

2167                          box_signature, &jargs, CHECK_NULL);
2168   oop hotspot_box = box_result.get_oop();
2169   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2170   return JVMCIENV->get_jobject(result);
2171 C2V_END
2172 
2173 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2174   Klass* klass = UNPACK_PAIR(Klass, klass);
2175   if (klass == nullptr) {
2176     JVMCI_THROW_NULL(NullPointerException);
2177   }
2178   if (!klass->is_instance_klass()) {
2179     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2180     return JVMCIENV->get_jobjectArray(methods);
2181   }
2182 
2183   InstanceKlass* iklass = InstanceKlass::cast(klass);
2184   GrowableArray<Method*> constructors_array;
2185   for (int i = 0; i < iklass->methods()->length(); i++) {
2186     Method* m = iklass->methods()->at(i);
2187     if (m->is_object_initializer()) {
2188       constructors_array.append(m);
2189     }
2190   }
2191   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2192   for (int i = 0; i < constructors_array.length(); i++) {
2193     methodHandle ctor(THREAD, constructors_array.at(i));
2194     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2195     JVMCIENV->put_object_at(methods, i, method);
2196   }
2197   return JVMCIENV->get_jobjectArray(methods);
2198 C2V_END
2199 
2200 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2201   Klass* klass = UNPACK_PAIR(Klass, klass);
2202   if (klass == nullptr) {
2203     JVMCI_THROW_NULL(NullPointerException);
2204   }
2205   if (!klass->is_instance_klass()) {
2206     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2207     return JVMCIENV->get_jobjectArray(methods);
2208   }
2209 
2210   InstanceKlass* iklass = InstanceKlass::cast(klass);
2211   GrowableArray<Method*> methods_array;
2212   for (int i = 0; i < iklass->methods()->length(); i++) {
2213     Method* m = iklass->methods()->at(i);
2214     if (!m->is_object_initializer() && !m->is_static_initializer() && !m->is_overpass()) {
2215       methods_array.append(m);
2216     }
2217   }
2218   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2219   for (int i = 0; i < methods_array.length(); i++) {
2220     methodHandle mh(THREAD, methods_array.at(i));
2221     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2222     JVMCIENV->put_object_at(methods, i, method);
2223   }
2224   return JVMCIENV->get_jobjectArray(methods);
2225 C2V_END
2226 
2227 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2228   Klass* klass = UNPACK_PAIR(Klass, klass);
2229   if (klass == nullptr) {
2230     JVMCI_THROW_NULL(NullPointerException);
2231   }
2232   if (!klass->is_instance_klass()) {
2233     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2234   }

2910 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2911   JVMCIObject code = JVMCIENV->wrap(code_handle);
2912   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2913   if (cb == nullptr) {
2914     return nullptr;
2915   }
2916   // Make a resource copy of code before the allocation causes a safepoint
2917   int code_size = cb->code_size();
2918   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2919   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2920 
2921   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2922   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2923   return JVMCIENV->get_jbyteArray(result);
2924 C2V_END
2925 
2926 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2927   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2928   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2929   oop executable;
2930   if (m->is_object_initializer()) {




2931     executable = Reflection::new_constructor(m, CHECK_NULL);
2932   } else if (m->is_static_initializer()) {
2933     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2934         "Cannot create java.lang.reflect.Method for class initializer");
2935   } else {
2936     executable = Reflection::new_method(m, false, CHECK_NULL);
2937   }
2938   return JNIHandles::make_local(THREAD, executable);
2939 C2V_END
2940 
2941 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2942   if (!klass->is_instance_klass()) {
2943     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2944         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2945   }
2946   InstanceKlass* iklass = InstanceKlass::cast(klass);
2947   if (index < 0 || index > iklass->total_fields_count()) {
2948     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2949         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2950   }
2951   return iklass;
2952 }
2953 
2954 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))

1588         if (vf->is_compiled_frame()) {
1589           // compiled method frame
1590           compiledVFrame* cvf = compiledVFrame::cast(vf);
1591 
1592           ScopeDesc* scope = cvf->scope();
1593           // native wrappers do not have a scope
1594           if (scope != nullptr && scope->objects() != nullptr) {
1595             prev_cvf = cvf;
1596 
1597             GrowableArray<ScopeValue*>* objects = nullptr;
1598             if (!realloc_called) {
1599               objects = scope->objects();
1600             } else {
1601               // some object might already have been re-allocated, only reallocate the non-allocated ones
1602               objects = get_unallocated_objects_or_null(scope->objects());
1603             }
1604 
1605             if (objects != nullptr) {
1606               RegisterMap reg_map(vf->register_map());
1607               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1608               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false, CHECK_NULL);
1609               realloc_called = true;
1610             }
1611 
1612             GrowableArray<ScopeValue*>* local_values = scope->locals();
1613             for (int i = 0; i < local_values->length(); i++) {
1614               ScopeValue* value = local_values->at(i);
1615               assert(!value->is_object_merge(), "Should not be.");
1616               if (value->is_object()) {
1617                 if (localIsVirtual_h.is_null()) {
1618                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1619                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1620                 }
1621                 localIsVirtual_h->bool_at_put(i, true);
1622               }
1623             }
1624           }
1625 
1626           locals = cvf->locals();
1627           frame_number = cvf->vframe_id();
1628         } else {

1839       break;
1840     }
1841     vf = vf->sender();
1842   }
1843 
1844   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1845   if (last_frame_number >= virtualFrames->length()) {
1846     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1847   }
1848 
1849   // Reallocate the non-escaping objects and restore their fields.
1850   assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1851   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1852 
1853   if (objects == nullptr) {
1854     // no objects to materialize
1855     return;
1856   }
1857 
1858   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1859   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1860 
1861   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1862     compiledVFrame* cvf = virtualFrames->at(frame_index);
1863 
1864     GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1865     StackValueCollection* locals = cvf->locals();
1866     if (locals != nullptr) {
1867       for (int i2 = 0; i2 < locals->size(); i2++) {
1868         StackValue* var = locals->at(i2);
1869         assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1870         if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1871           jvalue val;
1872           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1873           cvf->update_local(T_OBJECT, i2, val);
1874         }
1875       }
1876     }
1877 
1878     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1879     StackValueCollection* expressions = cvf->expressions();

2167                          box_signature, &jargs, CHECK_NULL);
2168   oop hotspot_box = box_result.get_oop();
2169   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2170   return JVMCIENV->get_jobject(result);
2171 C2V_END
2172 
2173 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2174   Klass* klass = UNPACK_PAIR(Klass, klass);
2175   if (klass == nullptr) {
2176     JVMCI_THROW_NULL(NullPointerException);
2177   }
2178   if (!klass->is_instance_klass()) {
2179     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2180     return JVMCIENV->get_jobjectArray(methods);
2181   }
2182 
2183   InstanceKlass* iklass = InstanceKlass::cast(klass);
2184   GrowableArray<Method*> constructors_array;
2185   for (int i = 0; i < iklass->methods()->length(); i++) {
2186     Method* m = iklass->methods()->at(i);
2187     if (m->is_object_constructor()) {
2188       constructors_array.append(m);
2189     }
2190   }
2191   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2192   for (int i = 0; i < constructors_array.length(); i++) {
2193     methodHandle ctor(THREAD, constructors_array.at(i));
2194     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2195     JVMCIENV->put_object_at(methods, i, method);
2196   }
2197   return JVMCIENV->get_jobjectArray(methods);
2198 C2V_END
2199 
2200 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2201   Klass* klass = UNPACK_PAIR(Klass, klass);
2202   if (klass == nullptr) {
2203     JVMCI_THROW_NULL(NullPointerException);
2204   }
2205   if (!klass->is_instance_klass()) {
2206     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2207     return JVMCIENV->get_jobjectArray(methods);
2208   }
2209 
2210   InstanceKlass* iklass = InstanceKlass::cast(klass);
2211   GrowableArray<Method*> methods_array;
2212   for (int i = 0; i < iklass->methods()->length(); i++) {
2213     Method* m = iklass->methods()->at(i);
2214     if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
2215       methods_array.append(m);
2216     }
2217   }
2218   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2219   for (int i = 0; i < methods_array.length(); i++) {
2220     methodHandle mh(THREAD, methods_array.at(i));
2221     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2222     JVMCIENV->put_object_at(methods, i, method);
2223   }
2224   return JVMCIENV->get_jobjectArray(methods);
2225 C2V_END
2226 
2227 C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2228   Klass* klass = UNPACK_PAIR(Klass, klass);
2229   if (klass == nullptr) {
2230     JVMCI_THROW_NULL(NullPointerException);
2231   }
2232   if (!klass->is_instance_klass()) {
2233     JVMCI_THROW_MSG_NULL(IllegalArgumentException, "not an InstanceKlass");
2234   }

2910 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2911   JVMCIObject code = JVMCIENV->wrap(code_handle);
2912   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2913   if (cb == nullptr) {
2914     return nullptr;
2915   }
2916   // Make a resource copy of code before the allocation causes a safepoint
2917   int code_size = cb->code_size();
2918   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2919   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2920 
2921   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2922   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2923   return JVMCIENV->get_jbyteArray(result);
2924 C2V_END
2925 
2926 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2927   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2928   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2929   oop executable;
2930   if (m->is_class_initializer()) {
2931       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2932           "Cannot create java.lang.reflect.Method for class initializer");
2933   }
2934   else if (m->is_object_constructor()) {
2935     executable = Reflection::new_constructor(m, CHECK_NULL);



2936   } else {
2937     executable = Reflection::new_method(m, false, CHECK_NULL);
2938   }
2939   return JNIHandles::make_local(THREAD, executable);
2940 C2V_END
2941 
2942 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2943   if (!klass->is_instance_klass()) {
2944     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2945         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2946   }
2947   InstanceKlass* iklass = InstanceKlass::cast(klass);
2948   if (index < 0 || index > iklass->total_fields_count()) {
2949     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2950         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2951   }
2952   return iklass;
2953 }
2954 
2955 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))
< prev index next >