32 #include "code/nmethod.hpp"
33 #include "code/pcDesc.hpp"
34 #include "code/scopeDesc.hpp"
35 #include "compiler/compilationPolicy.hpp"
36 #include "interpreter/bytecode.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/oopMapCache.hpp"
39 #include "memory/allocation.inline.hpp"
40 #include "memory/oopFactory.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.hpp"
43 #include "oops/constantPool.hpp"
44 #include "oops/method.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/objArrayOop.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "oops/fieldStreams.inline.hpp"
49 #include "oops/typeArrayOop.inline.hpp"
50 #include "oops/verifyOopClosure.hpp"
51 #include "prims/jvmtiThreadState.hpp"
52 #include "runtime/atomic.hpp"
53 #include "runtime/biasedLocking.hpp"
54 #include "runtime/deoptimization.hpp"
55 #include "runtime/fieldDescriptor.hpp"
56 #include "runtime/fieldDescriptor.inline.hpp"
57 #include "runtime/frame.inline.hpp"
58 #include "runtime/handles.inline.hpp"
59 #include "runtime/interfaceSupport.inline.hpp"
60 #include "runtime/jniHandles.inline.hpp"
61 #include "runtime/safepointVerifiers.hpp"
62 #include "runtime/sharedRuntime.hpp"
63 #include "runtime/signature.hpp"
64 #include "runtime/stubRoutines.hpp"
65 #include "runtime/thread.hpp"
66 #include "runtime/threadSMR.hpp"
67 #include "runtime/vframe.hpp"
68 #include "runtime/vframeArray.hpp"
69 #include "runtime/vframe_hp.hpp"
70 #include "utilities/events.hpp"
71 #include "utilities/macros.hpp"
985 assert(objects->at(i)->is_object(), "invalid debug information");
986 ObjectValue* sv = (ObjectValue*) objects->at(i);
987
988 Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
989 oop obj = NULL;
990
991 if (k->is_instance_klass()) {
992 #if INCLUDE_JVMCI || INCLUDE_AOT
993 CompiledMethod* cm = fr->cb()->as_compiled_method_or_null();
994 if (cm->is_compiled_by_jvmci() && sv->is_auto_box()) {
995 AutoBoxObjectValue* abv = (AutoBoxObjectValue*) sv;
996 obj = get_cached_box(abv, fr, reg_map, THREAD);
997 if (obj != NULL) {
998 // Set the flag to indicate the box came from a cache, so that we can skip the field reassignment for it.
999 abv->set_cached(true);
1000 }
1001 }
1002 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1003 InstanceKlass* ik = InstanceKlass::cast(k);
1004 if (obj == NULL) {
1005 obj = ik->allocate_instance(THREAD);
1006 }
1007 } else if (k->is_typeArray_klass()) {
1008 TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1009 assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
1010 int len = sv->field_size() / type2size[ak->element_type()];
1011 obj = ak->allocate(len, THREAD);
1012 } else if (k->is_objArray_klass()) {
1013 ObjArrayKlass* ak = ObjArrayKlass::cast(k);
1014 obj = ak->allocate(sv->field_size(), THREAD);
1015 }
1016
1017 if (obj == NULL) {
1018 failures = true;
1019 }
1020
1021 assert(sv->value().is_null(), "redundant reallocation");
1022 assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
1023 CLEAR_PENDING_EXCEPTION;
1024 sv->set_value(obj);
1025 }
1322
1323 // restore fields of all eliminated objects and arrays
1324 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
1325 for (int i = 0; i < objects->length(); i++) {
1326 ObjectValue* sv = (ObjectValue*) objects->at(i);
1327 Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1328 Handle obj = sv->value();
1329 assert(obj.not_null() || realloc_failures, "reallocation was missed");
1330 if (PrintDeoptimizationDetails) {
1331 tty->print_cr("reassign fields for object of type %s!", k->name()->as_C_string());
1332 }
1333 if (obj.is_null()) {
1334 continue;
1335 }
1336 #if INCLUDE_JVMCI || INCLUDE_AOT
1337 // Don't reassign fields of boxes that came from a cache. Caches may be in CDS.
1338 if (sv->is_auto_box() && ((AutoBoxObjectValue*) sv)->is_cached()) {
1339 continue;
1340 }
1341 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1342 if (k->is_instance_klass()) {
1343 InstanceKlass* ik = InstanceKlass::cast(k);
1344 reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
1345 } else if (k->is_typeArray_klass()) {
1346 TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1347 reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1348 } else if (k->is_objArray_klass()) {
1349 reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1350 }
1351 }
1352 }
1353
1354
1355 // relock objects for which synchronization was eliminated
1356 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1357 for (int i = 0; i < monitors->length(); i++) {
1358 MonitorInfo* mon_info = monitors->at(i);
1359 if (mon_info->eliminated()) {
1360 assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1361 if (!mon_info->owner_is_scalar_replaced()) {
|
32 #include "code/nmethod.hpp"
33 #include "code/pcDesc.hpp"
34 #include "code/scopeDesc.hpp"
35 #include "compiler/compilationPolicy.hpp"
36 #include "interpreter/bytecode.hpp"
37 #include "interpreter/interpreter.hpp"
38 #include "interpreter/oopMapCache.hpp"
39 #include "memory/allocation.inline.hpp"
40 #include "memory/oopFactory.hpp"
41 #include "memory/resourceArea.hpp"
42 #include "memory/universe.hpp"
43 #include "oops/constantPool.hpp"
44 #include "oops/method.hpp"
45 #include "oops/objArrayKlass.hpp"
46 #include "oops/objArrayOop.inline.hpp"
47 #include "oops/oop.inline.hpp"
48 #include "oops/fieldStreams.inline.hpp"
49 #include "oops/typeArrayOop.inline.hpp"
50 #include "oops/verifyOopClosure.hpp"
51 #include "prims/jvmtiThreadState.hpp"
52 #include "prims/vectorSupport.hpp"
53 #include "runtime/atomic.hpp"
54 #include "runtime/biasedLocking.hpp"
55 #include "runtime/deoptimization.hpp"
56 #include "runtime/fieldDescriptor.hpp"
57 #include "runtime/fieldDescriptor.inline.hpp"
58 #include "runtime/frame.inline.hpp"
59 #include "runtime/handles.inline.hpp"
60 #include "runtime/interfaceSupport.inline.hpp"
61 #include "runtime/jniHandles.inline.hpp"
62 #include "runtime/safepointVerifiers.hpp"
63 #include "runtime/sharedRuntime.hpp"
64 #include "runtime/signature.hpp"
65 #include "runtime/stubRoutines.hpp"
66 #include "runtime/thread.hpp"
67 #include "runtime/threadSMR.hpp"
68 #include "runtime/vframe.hpp"
69 #include "runtime/vframeArray.hpp"
70 #include "runtime/vframe_hp.hpp"
71 #include "utilities/events.hpp"
72 #include "utilities/macros.hpp"
986 assert(objects->at(i)->is_object(), "invalid debug information");
987 ObjectValue* sv = (ObjectValue*) objects->at(i);
988
989 Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
990 oop obj = NULL;
991
992 if (k->is_instance_klass()) {
993 #if INCLUDE_JVMCI || INCLUDE_AOT
994 CompiledMethod* cm = fr->cb()->as_compiled_method_or_null();
995 if (cm->is_compiled_by_jvmci() && sv->is_auto_box()) {
996 AutoBoxObjectValue* abv = (AutoBoxObjectValue*) sv;
997 obj = get_cached_box(abv, fr, reg_map, THREAD);
998 if (obj != NULL) {
999 // Set the flag to indicate the box came from a cache, so that we can skip the field reassignment for it.
1000 abv->set_cached(true);
1001 }
1002 }
1003 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1004 InstanceKlass* ik = InstanceKlass::cast(k);
1005 if (obj == NULL) {
1006 #ifdef COMPILER2
1007 if (EnableVectorSupport && VectorSupport::is_vector(ik)) {
1008 obj = VectorSupport::allocate_vector(ik, fr, reg_map, sv, THREAD);
1009 } else {
1010 obj = ik->allocate_instance(THREAD);
1011 }
1012 #else
1013 obj = ik->allocate_instance(THREAD);
1014 #endif // COMPILER2
1015 }
1016 } else if (k->is_typeArray_klass()) {
1017 TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1018 assert(sv->field_size() % type2size[ak->element_type()] == 0, "non-integral array length");
1019 int len = sv->field_size() / type2size[ak->element_type()];
1020 obj = ak->allocate(len, THREAD);
1021 } else if (k->is_objArray_klass()) {
1022 ObjArrayKlass* ak = ObjArrayKlass::cast(k);
1023 obj = ak->allocate(sv->field_size(), THREAD);
1024 }
1025
1026 if (obj == NULL) {
1027 failures = true;
1028 }
1029
1030 assert(sv->value().is_null(), "redundant reallocation");
1031 assert(obj != NULL || HAS_PENDING_EXCEPTION, "allocation should succeed or we should get an exception");
1032 CLEAR_PENDING_EXCEPTION;
1033 sv->set_value(obj);
1034 }
1331
1332 // restore fields of all eliminated objects and arrays
1333 void Deoptimization::reassign_fields(frame* fr, RegisterMap* reg_map, GrowableArray<ScopeValue*>* objects, bool realloc_failures, bool skip_internal) {
1334 for (int i = 0; i < objects->length(); i++) {
1335 ObjectValue* sv = (ObjectValue*) objects->at(i);
1336 Klass* k = java_lang_Class::as_Klass(sv->klass()->as_ConstantOopReadValue()->value()());
1337 Handle obj = sv->value();
1338 assert(obj.not_null() || realloc_failures, "reallocation was missed");
1339 if (PrintDeoptimizationDetails) {
1340 tty->print_cr("reassign fields for object of type %s!", k->name()->as_C_string());
1341 }
1342 if (obj.is_null()) {
1343 continue;
1344 }
1345 #if INCLUDE_JVMCI || INCLUDE_AOT
1346 // Don't reassign fields of boxes that came from a cache. Caches may be in CDS.
1347 if (sv->is_auto_box() && ((AutoBoxObjectValue*) sv)->is_cached()) {
1348 continue;
1349 }
1350 #endif // INCLUDE_JVMCI || INCLUDE_AOT
1351 #ifdef COMPILER2
1352 if (EnableVectorSupport && VectorSupport::is_vector(k)) {
1353 continue; // skip field reassignment for vectors
1354 }
1355 #endif
1356 if (k->is_instance_klass()) {
1357 InstanceKlass* ik = InstanceKlass::cast(k);
1358 reassign_fields_by_klass(ik, fr, reg_map, sv, 0, obj(), skip_internal);
1359 } else if (k->is_typeArray_klass()) {
1360 TypeArrayKlass* ak = TypeArrayKlass::cast(k);
1361 reassign_type_array_elements(fr, reg_map, sv, (typeArrayOop) obj(), ak->element_type());
1362 } else if (k->is_objArray_klass()) {
1363 reassign_object_array_elements(fr, reg_map, sv, (objArrayOop) obj());
1364 }
1365 }
1366 }
1367
1368
1369 // relock objects for which synchronization was eliminated
1370 void Deoptimization::relock_objects(GrowableArray<MonitorInfo*>* monitors, JavaThread* thread, bool realloc_failures) {
1371 for (int i = 0; i < monitors->length(); i++) {
1372 MonitorInfo* mon_info = monitors->at(i);
1373 if (mon_info->eliminated()) {
1374 assert(!mon_info->owner_is_scalar_replaced() || realloc_failures, "reallocation was missed");
1375 if (!mon_info->owner_is_scalar_replaced()) {
|