< prev index next >

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Print this page

1610         if (vf->is_compiled_frame()) {
1611           // compiled method frame
1612           compiledVFrame* cvf = compiledVFrame::cast(vf);
1613 
1614           ScopeDesc* scope = cvf->scope();
1615           // native wrappers do not have a scope
1616           if (scope != nullptr && scope->objects() != nullptr) {
1617             prev_cvf = cvf;
1618 
1619             GrowableArray<ScopeValue*>* objects = nullptr;
1620             if (!realloc_called) {
1621               objects = scope->objects();
1622             } else {
1623               // some object might already have been re-allocated, only reallocate the non-allocated ones
1624               objects = get_unallocated_objects_or_null(scope->objects());
1625             }
1626 
1627             if (objects != nullptr) {
1628               RegisterMap reg_map(vf->register_map());
1629               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1630               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false);
1631               realloc_called = true;
1632             }
1633 
1634             GrowableArray<ScopeValue*>* local_values = scope->locals();
1635             for (int i = 0; i < local_values->length(); i++) {
1636               ScopeValue* value = local_values->at(i);
1637               assert(!value->is_object_merge(), "Should not be.");
1638               if (value->is_object()) {
1639                 if (localIsVirtual_h.is_null()) {
1640                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1641                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1642                 }
1643                 localIsVirtual_h->bool_at_put(i, true);
1644               }
1645             }
1646           }
1647 
1648           locals = cvf->locals();
1649           frame_number = cvf->vframe_id();
1650         } else {

1861       break;
1862     }
1863     vf = vf->sender();
1864   }
1865 
1866   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1867   if (last_frame_number >= virtualFrames->length()) {
1868     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1869   }
1870 
1871   // Reallocate the non-escaping objects and restore their fields.
1872   assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1873   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1874 
1875   if (objects == nullptr) {
1876     // no objects to materialize
1877     return;
1878   }
1879 
1880   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1881   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false);
1882 
1883   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1884     compiledVFrame* cvf = virtualFrames->at(frame_index);
1885 
1886     GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1887     StackValueCollection* locals = cvf->locals();
1888     if (locals != nullptr) {
1889       for (int i2 = 0; i2 < locals->size(); i2++) {
1890         StackValue* var = locals->at(i2);
1891         assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1892         if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1893           jvalue val;
1894           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1895           cvf->update_local(T_OBJECT, i2, val);
1896         }
1897       }
1898     }
1899 
1900     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1901     StackValueCollection* expressions = cvf->expressions();

2189                          box_signature, &jargs, CHECK_NULL);
2190   oop hotspot_box = box_result.get_oop();
2191   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2192   return JVMCIENV->get_jobject(result);
2193 C2V_END
2194 
2195 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2196   Klass* klass = UNPACK_PAIR(Klass, klass);
2197   if (klass == nullptr) {
2198     JVMCI_THROW_NULL(NullPointerException);
2199   }
2200   if (!klass->is_instance_klass()) {
2201     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2202     return JVMCIENV->get_jobjectArray(methods);
2203   }
2204 
2205   InstanceKlass* iklass = InstanceKlass::cast(klass);
2206   GrowableArray<Method*> constructors_array;
2207   for (int i = 0; i < iklass->methods()->length(); i++) {
2208     Method* m = iklass->methods()->at(i);
2209     if (m->is_object_initializer()) {
2210       constructors_array.append(m);
2211     }
2212   }
2213   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2214   for (int i = 0; i < constructors_array.length(); i++) {
2215     methodHandle ctor(THREAD, constructors_array.at(i));
2216     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2217     JVMCIENV->put_object_at(methods, i, method);
2218   }
2219   return JVMCIENV->get_jobjectArray(methods);
2220 C2V_END
2221 
2222 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2223   Klass* klass = UNPACK_PAIR(Klass, klass);
2224   if (klass == nullptr) {
2225     JVMCI_THROW_NULL(NullPointerException);
2226   }
2227   if (!klass->is_instance_klass()) {
2228     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2229     return JVMCIENV->get_jobjectArray(methods);
2230   }
2231 
2232   InstanceKlass* iklass = InstanceKlass::cast(klass);
2233   GrowableArray<Method*> methods_array;
2234   for (int i = 0; i < iklass->methods()->length(); i++) {
2235     Method* m = iklass->methods()->at(i);
2236     if (!m->is_object_initializer() && !m->is_static_initializer() && !m->is_overpass()) {
2237       methods_array.append(m);
2238     }
2239   }
2240   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2241   for (int i = 0; i < methods_array.length(); i++) {
2242     methodHandle mh(THREAD, methods_array.at(i));
2243     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2244     JVMCIENV->put_object_at(methods, i, method);
2245   }
2246   return JVMCIENV->get_jobjectArray(methods);
2247 C2V_END
2248 
2249 C2V_VMENTRY_NULL(jobjectArray, getAllMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2250   Klass* klass = UNPACK_PAIR(Klass, klass);
2251   if (klass == nullptr) {
2252     JVMCI_THROW_NULL(NullPointerException);
2253   }
2254   if (!klass->is_instance_klass()) {
2255     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2256     return JVMCIENV->get_jobjectArray(methods);

2956 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2957   JVMCIObject code = JVMCIENV->wrap(code_handle);
2958   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2959   if (cb == nullptr) {
2960     return nullptr;
2961   }
2962   // Make a resource copy of code before the allocation causes a safepoint
2963   int code_size = cb->code_size();
2964   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2965   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2966 
2967   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2968   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2969   return JVMCIENV->get_jbyteArray(result);
2970 C2V_END
2971 
2972 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2973   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2974   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2975   oop executable;
2976   if (m->is_object_initializer()) {




2977     executable = Reflection::new_constructor(m, CHECK_NULL);
2978   } else if (m->is_static_initializer()) {
2979     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2980         "Cannot create java.lang.reflect.Method for class initializer");
2981   } else {
2982     executable = Reflection::new_method(m, false, CHECK_NULL);
2983   }
2984   return JNIHandles::make_local(THREAD, executable);
2985 C2V_END
2986 
2987 // Checks that `index` denotes a non-injected field in `klass`
2988 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2989   if (!klass->is_instance_klass()) {
2990     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2991         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2992   }
2993   InstanceKlass* iklass = InstanceKlass::cast(klass);
2994   if (index < 0 || index >= iklass->java_fields_count()) {
2995     if (index >= 0 && index < iklass->total_fields_count()) {
2996       fieldDescriptor fd(iklass, index);
2997       if (fd.is_injected()) {
2998         JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2999             err_msg("Cannot get Field for injected %s.%s", klass->external_name(), fd.name()->as_C_string()));
3000       }

1610         if (vf->is_compiled_frame()) {
1611           // compiled method frame
1612           compiledVFrame* cvf = compiledVFrame::cast(vf);
1613 
1614           ScopeDesc* scope = cvf->scope();
1615           // native wrappers do not have a scope
1616           if (scope != nullptr && scope->objects() != nullptr) {
1617             prev_cvf = cvf;
1618 
1619             GrowableArray<ScopeValue*>* objects = nullptr;
1620             if (!realloc_called) {
1621               objects = scope->objects();
1622             } else {
1623               // some object might already have been re-allocated, only reallocate the non-allocated ones
1624               objects = get_unallocated_objects_or_null(scope->objects());
1625             }
1626 
1627             if (objects != nullptr) {
1628               RegisterMap reg_map(vf->register_map());
1629               bool realloc_failures = Deoptimization::realloc_objects(thread, vf->frame_pointer(), &reg_map, objects, CHECK_NULL);
1630               Deoptimization::reassign_fields(vf->frame_pointer(), &reg_map, objects, realloc_failures, false, CHECK_NULL);
1631               realloc_called = true;
1632             }
1633 
1634             GrowableArray<ScopeValue*>* local_values = scope->locals();
1635             for (int i = 0; i < local_values->length(); i++) {
1636               ScopeValue* value = local_values->at(i);
1637               assert(!value->is_object_merge(), "Should not be.");
1638               if (value->is_object()) {
1639                 if (localIsVirtual_h.is_null()) {
1640                   typeArrayOop array_oop = oopFactory::new_boolArray(local_values->length(), CHECK_NULL);
1641                   localIsVirtual_h = typeArrayHandle(THREAD, array_oop);
1642                 }
1643                 localIsVirtual_h->bool_at_put(i, true);
1644               }
1645             }
1646           }
1647 
1648           locals = cvf->locals();
1649           frame_number = cvf->vframe_id();
1650         } else {

1861       break;
1862     }
1863     vf = vf->sender();
1864   }
1865 
1866   int last_frame_number = JVMCIENV->get_HotSpotStackFrameReference_frameNumber(hs_frame);
1867   if (last_frame_number >= virtualFrames->length()) {
1868     JVMCI_THROW_MSG(IllegalStateException, "invalid frame number");
1869   }
1870 
1871   // Reallocate the non-escaping objects and restore their fields.
1872   assert (virtualFrames->at(last_frame_number)->scope() != nullptr,"invalid scope");
1873   GrowableArray<ScopeValue*>* objects = virtualFrames->at(last_frame_number)->scope()->objects();
1874 
1875   if (objects == nullptr) {
1876     // no objects to materialize
1877     return;
1878   }
1879 
1880   bool realloc_failures = Deoptimization::realloc_objects(thread, fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, CHECK);
1881   Deoptimization::reassign_fields(fstAfterDeopt.current(), fstAfterDeopt.register_map(), objects, realloc_failures, false, THREAD);
1882 
1883   for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
1884     compiledVFrame* cvf = virtualFrames->at(frame_index);
1885 
1886     GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
1887     StackValueCollection* locals = cvf->locals();
1888     if (locals != nullptr) {
1889       for (int i2 = 0; i2 < locals->size(); i2++) {
1890         StackValue* var = locals->at(i2);
1891         assert(!scopedValues->at(i2)->is_object_merge(), "Should not be.");
1892         if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
1893           jvalue val;
1894           val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
1895           cvf->update_local(T_OBJECT, i2, val);
1896         }
1897       }
1898     }
1899 
1900     GrowableArray<ScopeValue*>* scopeExpressions = cvf->scope()->expressions();
1901     StackValueCollection* expressions = cvf->expressions();

2189                          box_signature, &jargs, CHECK_NULL);
2190   oop hotspot_box = box_result.get_oop();
2191   JVMCIObject result = JVMCIENV->get_object_constant(hotspot_box, false);
2192   return JVMCIENV->get_jobject(result);
2193 C2V_END
2194 
2195 C2V_VMENTRY_NULL(jobjectArray, getDeclaredConstructors, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2196   Klass* klass = UNPACK_PAIR(Klass, klass);
2197   if (klass == nullptr) {
2198     JVMCI_THROW_NULL(NullPointerException);
2199   }
2200   if (!klass->is_instance_klass()) {
2201     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2202     return JVMCIENV->get_jobjectArray(methods);
2203   }
2204 
2205   InstanceKlass* iklass = InstanceKlass::cast(klass);
2206   GrowableArray<Method*> constructors_array;
2207   for (int i = 0; i < iklass->methods()->length(); i++) {
2208     Method* m = iklass->methods()->at(i);
2209     if (m->is_object_constructor()) {
2210       constructors_array.append(m);
2211     }
2212   }
2213   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(constructors_array.length(), JVMCI_CHECK_NULL);
2214   for (int i = 0; i < constructors_array.length(); i++) {
2215     methodHandle ctor(THREAD, constructors_array.at(i));
2216     JVMCIObject method = JVMCIENV->get_jvmci_method(ctor, JVMCI_CHECK_NULL);
2217     JVMCIENV->put_object_at(methods, i, method);
2218   }
2219   return JVMCIENV->get_jobjectArray(methods);
2220 C2V_END
2221 
2222 C2V_VMENTRY_NULL(jobjectArray, getDeclaredMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2223   Klass* klass = UNPACK_PAIR(Klass, klass);
2224   if (klass == nullptr) {
2225     JVMCI_THROW_NULL(NullPointerException);
2226   }
2227   if (!klass->is_instance_klass()) {
2228     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2229     return JVMCIENV->get_jobjectArray(methods);
2230   }
2231 
2232   InstanceKlass* iklass = InstanceKlass::cast(klass);
2233   GrowableArray<Method*> methods_array;
2234   for (int i = 0; i < iklass->methods()->length(); i++) {
2235     Method* m = iklass->methods()->at(i);
2236     if (!(m->is_object_constructor() || m->is_class_initializer()) && !m->is_overpass()) {
2237       methods_array.append(m);
2238     }
2239   }
2240   JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(methods_array.length(), JVMCI_CHECK_NULL);
2241   for (int i = 0; i < methods_array.length(); i++) {
2242     methodHandle mh(THREAD, methods_array.at(i));
2243     JVMCIObject method = JVMCIENV->get_jvmci_method(mh, JVMCI_CHECK_NULL);
2244     JVMCIENV->put_object_at(methods, i, method);
2245   }
2246   return JVMCIENV->get_jobjectArray(methods);
2247 C2V_END
2248 
2249 C2V_VMENTRY_NULL(jobjectArray, getAllMethods, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass)))
2250   Klass* klass = UNPACK_PAIR(Klass, klass);
2251   if (klass == nullptr) {
2252     JVMCI_THROW_NULL(NullPointerException);
2253   }
2254   if (!klass->is_instance_klass()) {
2255     JVMCIObjectArray methods = JVMCIENV->new_ResolvedJavaMethod_array(0, JVMCI_CHECK_NULL);
2256     return JVMCIENV->get_jobjectArray(methods);

2956 C2V_VMENTRY_NULL(jbyteArray, getCode, (JNIEnv* env, jobject, jobject code_handle))
2957   JVMCIObject code = JVMCIENV->wrap(code_handle);
2958   CodeBlob* cb = JVMCIENV->get_code_blob(code);
2959   if (cb == nullptr) {
2960     return nullptr;
2961   }
2962   // Make a resource copy of code before the allocation causes a safepoint
2963   int code_size = cb->code_size();
2964   jbyte* code_bytes = NEW_RESOURCE_ARRAY(jbyte, code_size);
2965   memcpy(code_bytes, (jbyte*) cb->code_begin(), code_size);
2966 
2967   JVMCIPrimitiveArray result = JVMCIENV->new_byteArray(code_size, JVMCI_CHECK_NULL);
2968   JVMCIENV->copy_bytes_from(code_bytes, result, 0, code_size);
2969   return JVMCIENV->get_jbyteArray(result);
2970 C2V_END
2971 
2972 C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMENT_PAIR(method)))
2973   requireInHotSpot("asReflectionExecutable", JVMCI_CHECK_NULL);
2974   methodHandle m(THREAD, UNPACK_PAIR(Method, method));
2975   oop executable;
2976   if (m->is_class_initializer()) {
2977       JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2978           "Cannot create java.lang.reflect.Method for class initializer");
2979   }
2980   else if (m->is_object_constructor()) {
2981     executable = Reflection::new_constructor(m, CHECK_NULL);



2982   } else {
2983     executable = Reflection::new_method(m, false, CHECK_NULL);
2984   }
2985   return JNIHandles::make_local(THREAD, executable);
2986 C2V_END
2987 
2988 // Checks that `index` denotes a non-injected field in `klass`
2989 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2990   if (!klass->is_instance_klass()) {
2991     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2992         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2993   }
2994   InstanceKlass* iklass = InstanceKlass::cast(klass);
2995   if (index < 0 || index >= iklass->java_fields_count()) {
2996     if (index >= 0 && index < iklass->total_fields_count()) {
2997       fieldDescriptor fd(iklass, index);
2998       if (fd.is_injected()) {
2999         JVMCI_THROW_MSG_NULL(IllegalArgumentException,
3000             err_msg("Cannot get Field for injected %s.%s", klass->external_name(), fd.name()->as_C_string()));
3001       }
< prev index next >