< 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);

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




2976     executable = Reflection::new_constructor(m, CHECK_NULL);
2977   } else if (m->is_static_initializer()) {
2978     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2979         "Cannot create java.lang.reflect.Method for class initializer");
2980   } else {
2981     executable = Reflection::new_method(m, false, CHECK_NULL);
2982   }
2983   return JNIHandles::make_local(THREAD, executable);
2984 C2V_END
2985 
2986 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2987   if (!klass->is_instance_klass()) {
2988     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2989         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2990   }
2991   InstanceKlass* iklass = InstanceKlass::cast(klass);
2992   if (index < 0 || index > iklass->total_fields_count()) {
2993     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2994         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2995   }
2996   return iklass;
2997 }
2998 
2999 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))

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);

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



2981   } else {
2982     executable = Reflection::new_method(m, false, CHECK_NULL);
2983   }
2984   return JNIHandles::make_local(THREAD, executable);
2985 C2V_END
2986 
2987 static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) {
2988   if (!klass->is_instance_klass()) {
2989     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2990         err_msg("Expected non-primitive type, got %s", klass->external_name()));
2991   }
2992   InstanceKlass* iklass = InstanceKlass::cast(klass);
2993   if (index < 0 || index > iklass->total_fields_count()) {
2994     JVMCI_THROW_MSG_NULL(IllegalArgumentException,
2995         err_msg("Field index %d out of bounds for %s", index, klass->external_name()));
2996   }
2997   return iklass;
2998 }
2999 
3000 C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index))
< prev index next >