comparison src/share/vm/jvmci/jvmciCodeInstaller.cpp @ 23408:f84a5ac3be22

make JVMCI JDK immutable and sharable among different JVMCI clients minimize diff to jvmci-9, including adding support for EnableJVMCI (default is true in jvmci-8)
author Doug Simon <doug.simon@oracle.com>
date Mon, 30 May 2016 22:56:59 +0200
parents 9ed5b586018b
children eb166b568645
comparison
equal deleted inserted replaced
23407:a1d1f1e4817f 23408:f84a5ac3be22
68 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass()), "sanity"); 68 assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethodImpl::klass()), "sanity");
69 return CompilerToVM::asMethod(hotspot_method); 69 return CompilerToVM::asMethod(hotspot_method);
70 } 70 }
71 71
72 VMReg getVMRegFromLocation(Handle location, int total_frame_size, TRAPS) { 72 VMReg getVMRegFromLocation(Handle location, int total_frame_size, TRAPS) {
73 if (location.is_null()) {
74 THROW_NULL(vmSymbols::java_lang_NullPointerException());
75 }
76
73 Handle reg = code_Location::reg(location); 77 Handle reg = code_Location::reg(location);
74 jint offset = code_Location::offset(location); 78 jint offset = code_Location::offset(location);
75 79
76 if (reg.not_null()) { 80 if (reg.not_null()) {
77 // register 81 // register
93 } 97 }
94 98
95 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo 99 // creates a HotSpot oop map out of the byte arrays provided by DebugInfo
96 OopMap* CodeInstaller::create_oop_map(Handle debug_info, TRAPS) { 100 OopMap* CodeInstaller::create_oop_map(Handle debug_info, TRAPS) {
97 Handle reference_map = DebugInfo::referenceMap(debug_info); 101 Handle reference_map = DebugInfo::referenceMap(debug_info);
102 if (reference_map.is_null()) {
103 THROW_NULL(vmSymbols::java_lang_NullPointerException());
104 }
105 if (!reference_map->is_a(HotSpotReferenceMap::klass())) {
106 JVMCI_ERROR_NULL("unknown reference map: %s", reference_map->klass()->signature_name());
107 }
98 if (HotSpotReferenceMap::maxRegisterSize(reference_map) > 16) { 108 if (HotSpotReferenceMap::maxRegisterSize(reference_map) > 16) {
99 _has_wide_vector = true; 109 _has_wide_vector = true;
100 } 110 }
101 OopMap* map = new OopMap(_total_frame_size, _parameter_count); 111 OopMap* map = new OopMap(_total_frame_size, _parameter_count);
102 objArrayHandle objects = HotSpotReferenceMap::objects(reference_map); 112 objArrayHandle objects = HotSpotReferenceMap::objects(reference_map);
103 objArrayHandle derivedBase = HotSpotReferenceMap::derivedBase(reference_map); 113 objArrayHandle derivedBase = HotSpotReferenceMap::derivedBase(reference_map);
104 typeArrayHandle sizeInBytes = HotSpotReferenceMap::sizeInBytes(reference_map); 114 typeArrayHandle sizeInBytes = HotSpotReferenceMap::sizeInBytes(reference_map);
115 if (objects.is_null() || derivedBase.is_null() || sizeInBytes.is_null()) {
116 THROW_NULL(vmSymbols::java_lang_NullPointerException());
117 }
118 if (objects->length() != derivedBase->length() || objects->length() != sizeInBytes->length()) {
119 JVMCI_ERROR_NULL("arrays in reference map have different sizes: %d %d %d", objects->length(), derivedBase->length(), sizeInBytes->length());
120 }
105 for (int i = 0; i < objects->length(); i++) { 121 for (int i = 0; i < objects->length(); i++) {
106 Handle location = objects->obj_at(i); 122 Handle location = objects->obj_at(i);
107 Handle baseLocation = derivedBase->obj_at(i); 123 Handle baseLocation = derivedBase->obj_at(i);
108 int bytes = sizeInBytes->int_at(i); 124 int bytes = sizeInBytes->int_at(i);
109 125
161 177
162 void* CodeInstaller::record_metadata_reference(Handle constant, TRAPS) { 178 void* CodeInstaller::record_metadata_reference(Handle constant, TRAPS) {
163 /* 179 /*
164 * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base 180 * This method needs to return a raw (untyped) pointer, since the value of a pointer to the base
165 * class is in general not equal to the pointer of the subclass. When patching metaspace pointers, 181 * class is in general not equal to the pointer of the subclass. When patching metaspace pointers,
166 * the compiler expects a direct pointer to the subclass (Klass*, Method* or Symbol*), not a 182 * the compiler expects a direct pointer to the subclass (Klass* or Method*), not a pointer to the
167 * pointer to the base class (Metadata* or MetaspaceObj*). 183 * base class (Metadata* or MetaspaceObj*).
168 */ 184 */
169 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant); 185 oop obj = HotSpotMetaspaceConstantImpl::metaspaceObject(constant);
170 if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) { 186 if (obj->is_a(HotSpotResolvedObjectTypeImpl::klass())) {
171 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj)); 187 Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(obj));
172 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass))); 188 assert(!HotSpotMetaspaceConstantImpl::compressed(constant), err_msg("unexpected compressed klass pointer %s @ " INTPTR_FORMAT, klass->name()->as_C_string(), p2i(klass)));
201 #endif 217 #endif
202 218
203 Location::Type CodeInstaller::get_oop_type(Handle value) { 219 Location::Type CodeInstaller::get_oop_type(Handle value) {
204 Handle valueKind = Value::valueKind(value); 220 Handle valueKind = Value::valueKind(value);
205 Handle platformKind = ValueKind::platformKind(valueKind); 221 Handle platformKind = ValueKind::platformKind(valueKind);
206 222
207 if (platformKind == word_kind()) { 223 if (platformKind == word_kind()) {
208 return Location::oop; 224 return Location::oop;
209 } else { 225 } else {
210 return Location::narrowoop; 226 return Location::narrowoop;
211 } 227 }
212 } 228 }
213 229
214 ScopeValue* CodeInstaller::get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS) { 230 ScopeValue* CodeInstaller::get_scope_value(Handle value, BasicType type, GrowableArray<ScopeValue*>* objects, ScopeValue* &second, TRAPS) {
215 second = NULL; 231 second = NULL;
216 if (value == Value::ILLEGAL()) { 232 if (value.is_null()) {
233 THROW_NULL(vmSymbols::java_lang_NullPointerException());
234 } else if (value == Value::ILLEGAL()) {
217 if (type != T_ILLEGAL) { 235 if (type != T_ILLEGAL) {
218 JVMCI_ERROR_NULL("unexpected illegal value, expected %s", basictype_to_str(type)); 236 JVMCI_ERROR_NULL("unexpected illegal value, expected %s", basictype_to_str(type));
219 } 237 }
220 return _illegal_value; 238 return _illegal_value;
221 } else if (value->is_a(RegisterValue::klass())) { 239 } else if (value->is_a(RegisterValue::klass())) {
281 if (value->is_a(PrimitiveConstant::klass())) { 299 if (value->is_a(PrimitiveConstant::klass())) {
282 if (value->is_a(RawConstant::klass())) { 300 if (value->is_a(RawConstant::klass())) {
283 jlong prim = PrimitiveConstant::primitive(value); 301 jlong prim = PrimitiveConstant::primitive(value);
284 return new ConstantLongValue(prim); 302 return new ConstantLongValue(prim);
285 } else { 303 } else {
286 BasicType constantType = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(PrimitiveConstant::kind(value)), CHECK_NULL); 304 BasicType constantType = JVMCIRuntime::kindToBasicType(PrimitiveConstant::kind(value), CHECK_NULL);
287 if (type != constantType) { 305 if (type != constantType) {
288 JVMCI_ERROR_NULL("primitive constant type doesn't match, expected %s but got %s", basictype_to_str(type), basictype_to_str(constantType)); 306 JVMCI_ERROR_NULL("primitive constant type doesn't match, expected %s but got %s", basictype_to_str(type), basictype_to_str(constantType));
289 } 307 }
290 if (type == T_INT || type == T_FLOAT) { 308 if (type == T_INT || type == T_FLOAT) {
291 jint prim = (jint)PrimitiveConstant::primitive(value); 309 jint prim = (jint)PrimitiveConstant::primitive(value);
349 objArrayHandle values = VirtualObject::values(value); 367 objArrayHandle values = VirtualObject::values(value);
350 objArrayHandle slotKinds = VirtualObject::slotKinds(value); 368 objArrayHandle slotKinds = VirtualObject::slotKinds(value);
351 for (jint i = 0; i < values->length(); i++) { 369 for (jint i = 0; i < values->length(); i++) {
352 ScopeValue* cur_second = NULL; 370 ScopeValue* cur_second = NULL;
353 Handle object = values->obj_at(i); 371 Handle object = values->obj_at(i);
354 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(slotKinds->obj_at(i)), CHECK); 372 BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
355 ScopeValue* value = get_scope_value(object, type, objects, cur_second, CHECK); 373 ScopeValue* value = get_scope_value(object, type, objects, cur_second, CHECK);
356 374
357 if (isLongArray && cur_second == NULL) { 375 if (isLongArray && cur_second == NULL) {
358 // we're trying to put ints into a long array... this isn't really valid, but it's used for some optimizations. 376 // we're trying to put ints into a long array... this isn't really valid, but it's used for some optimizations.
359 // add an int 0 constant 377 // add an int 0 constant
367 sv->field_values()->append(value); 385 sv->field_values()->append(value);
368 } 386 }
369 } 387 }
370 388
371 MonitorValue* CodeInstaller::get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) { 389 MonitorValue* CodeInstaller::get_monitor_value(Handle value, GrowableArray<ScopeValue*>* objects, TRAPS) {
390 if (value.is_null()) {
391 THROW_NULL(vmSymbols::java_lang_NullPointerException());
392 }
372 if (!value->is_a(StackLockValue::klass())) { 393 if (!value->is_a(StackLockValue::klass())) {
373 JVMCI_ERROR_NULL("Monitors must be of type StackLockValue, got %s", value->klass()->signature_name()); 394 JVMCI_ERROR_NULL("Monitors must be of type StackLockValue, got %s", value->klass()->signature_name());
374 } 395 }
375 396
376 ScopeValue* second = NULL; 397 ScopeValue* second = NULL;
538 // Estimate the number of static call stubs that might be emitted. 559 // Estimate the number of static call stubs that might be emitted.
539 int static_call_stubs = 0; 560 int static_call_stubs = 0;
540 objArrayOop sites = this->sites(); 561 objArrayOop sites = this->sites();
541 for (int i = 0; i < sites->length(); i++) { 562 for (int i = 0; i < sites->length(); i++) {
542 oop site = sites->obj_at(i); 563 oop site = sites->obj_at(i);
543 if (site->is_a(site_Mark::klass())) { 564 if (site != NULL && site->is_a(site_Mark::klass())) {
544 oop id_obj = site_Mark::id(site); 565 oop id_obj = site_Mark::id(site);
545 if (id_obj != NULL) { 566 if (id_obj != NULL) {
546 if (!java_lang_boxing_object::is_instance(id_obj, T_INT)) { 567 if (!java_lang_boxing_object::is_instance(id_obj, T_INT)) {
547 JVMCI_ERROR_0("expected Integer id, got %s", id_obj->klass()->signature_name()); 568 JVMCI_ERROR_0("expected Integer id, got %s", id_obj->klass()->signature_name());
548 } 569 }
596 memcpy(_instructions->start(), code()->base(T_BYTE), _code_size); 617 memcpy(_instructions->start(), code()->base(T_BYTE), _code_size);
597 _instructions->set_end(end_pc); 618 _instructions->set_end(end_pc);
598 619
599 for (int i = 0; i < data_section_patches()->length(); i++) { 620 for (int i = 0; i < data_section_patches()->length(); i++) {
600 Handle patch = data_section_patches()->obj_at(i); 621 Handle patch = data_section_patches()->obj_at(i);
622 if (patch.is_null()) {
623 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
624 }
601 Handle reference = site_DataPatch::reference(patch); 625 Handle reference = site_DataPatch::reference(patch);
626 if (reference.is_null()) {
627 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
628 }
602 if (!reference->is_a(site_ConstantReference::klass())) { 629 if (!reference->is_a(site_ConstantReference::klass())) {
603 JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name()); 630 JVMCI_ERROR_OK("invalid patch in data section: %s", reference->klass()->signature_name());
604 } 631 }
605 Handle constant = site_ConstantReference::constant(reference); 632 Handle constant = site_ConstantReference::constant(reference);
633 if (constant.is_null()) {
634 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
635 }
606 address dest = _constants->start() + site_Site::pcOffset(patch); 636 address dest = _constants->start() + site_Site::pcOffset(patch);
607 if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) { 637 if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
608 if (HotSpotMetaspaceConstantImpl::compressed(constant)) { 638 if (HotSpotMetaspaceConstantImpl::compressed(constant)) {
609 #ifdef _LP64 639 #ifdef _LP64
610 *((narrowKlass*) dest) = record_narrow_metadata_reference(constant, CHECK_OK); 640 *((narrowKlass*) dest) = record_narrow_metadata_reference(constant, CHECK_OK);
633 } 663 }
634 } 664 }
635 jint last_pc_offset = -1; 665 jint last_pc_offset = -1;
636 for (int i = 0; i < sites->length(); i++) { 666 for (int i = 0; i < sites->length(); i++) {
637 Handle site = sites->obj_at(i); 667 Handle site = sites->obj_at(i);
668 if (site.is_null()) {
669 THROW_(vmSymbols::java_lang_NullPointerException(), JVMCIEnv::ok);
670 }
671
638 jint pc_offset = site_Site::pcOffset(site); 672 jint pc_offset = site_Site::pcOffset(site);
639 673
640 if (site->is_a(site_Call::klass())) { 674 if (site->is_a(site_Call::klass())) {
641 TRACE_jvmci_4("call at %i", pc_offset); 675 TRACE_jvmci_4("call at %i", pc_offset);
642 site_Call(buffer, pc_offset, site, CHECK_OK); 676 site_Call(buffer, pc_offset, site, CHECK_OK);
846 jint expression_count = BytecodeFrame::numStack(frame); 880 jint expression_count = BytecodeFrame::numStack(frame);
847 jint monitor_count = BytecodeFrame::numLocks(frame); 881 jint monitor_count = BytecodeFrame::numLocks(frame);
848 objArrayHandle values = BytecodeFrame::values(frame); 882 objArrayHandle values = BytecodeFrame::values(frame);
849 objArrayHandle slotKinds = BytecodeFrame::slotKinds(frame); 883 objArrayHandle slotKinds = BytecodeFrame::slotKinds(frame);
850 884
885 if (values.is_null() || slotKinds.is_null()) {
886 THROW(vmSymbols::java_lang_NullPointerException());
887 }
851 if (local_count + expression_count + monitor_count != values->length()) { 888 if (local_count + expression_count + monitor_count != values->length()) {
852 JVMCI_ERROR("unexpected values length %d in scope (%d locals, %d expressions, %d monitors)", values->length(), local_count, expression_count, monitor_count); 889 JVMCI_ERROR("unexpected values length %d in scope (%d locals, %d expressions, %d monitors)", values->length(), local_count, expression_count, monitor_count);
853 } 890 }
854 if (local_count + expression_count != slotKinds->length()) { 891 if (local_count + expression_count != slotKinds->length()) {
855 JVMCI_ERROR("unexpected slotKinds length %d in scope (%d locals, %d expressions)", slotKinds->length(), local_count, expression_count); 892 JVMCI_ERROR("unexpected slotKinds length %d in scope (%d locals, %d expressions)", slotKinds->length(), local_count, expression_count);
864 901
865 for (jint i = 0; i < values->length(); i++) { 902 for (jint i = 0; i < values->length(); i++) {
866 ScopeValue* second = NULL; 903 ScopeValue* second = NULL;
867 Handle value = values->obj_at(i); 904 Handle value = values->obj_at(i);
868 if (i < local_count) { 905 if (i < local_count) {
869 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(slotKinds->obj_at(i)), CHECK); 906 BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
870 ScopeValue* first = get_scope_value(value, type, objects, second, CHECK); 907 ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
871 if (second != NULL) { 908 if (second != NULL) {
872 locals->append(second); 909 locals->append(second);
873 } 910 }
874 locals->append(first); 911 locals->append(first);
875 } else if (i < local_count + expression_count) { 912 } else if (i < local_count + expression_count) {
876 BasicType type = JVMCIRuntime::kindToBasicType(JavaKind::typeChar(slotKinds->obj_at(i)), CHECK); 913 BasicType type = JVMCIRuntime::kindToBasicType(slotKinds->obj_at(i), CHECK);
877 ScopeValue* first = get_scope_value(value, type, objects, second, CHECK); 914 ScopeValue* first = get_scope_value(value, type, objects, second, CHECK);
878 if (second != NULL) { 915 if (second != NULL) {
879 expressions->append(second); 916 expressions->append(second);
880 } 917 }
881 expressions->append(first); 918 expressions->append(first);
980 } 1017 }
981 } 1018 }
982 1019
983 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) { 1020 void CodeInstaller::site_DataPatch(CodeBuffer& buffer, jint pc_offset, Handle site, TRAPS) {
984 Handle reference = site_DataPatch::reference(site); 1021 Handle reference = site_DataPatch::reference(site);
985 if (reference->is_a(site_ConstantReference::klass())) { 1022 if (reference.is_null()) {
1023 THROW(vmSymbols::java_lang_NullPointerException());
1024 } else if (reference->is_a(site_ConstantReference::klass())) {
986 Handle constant = site_ConstantReference::constant(reference); 1025 Handle constant = site_ConstantReference::constant(reference);
987 if (constant->is_a(HotSpotObjectConstantImpl::klass())) { 1026 if (constant.is_null()) {
1027 THROW(vmSymbols::java_lang_NullPointerException());
1028 } else if (constant->is_a(HotSpotObjectConstantImpl::klass())) {
988 pd_patch_OopConstant(pc_offset, constant, CHECK); 1029 pd_patch_OopConstant(pc_offset, constant, CHECK);
989 } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) { 1030 } else if (constant->is_a(HotSpotMetaspaceConstantImpl::klass())) {
990 pd_patch_MetaspaceConstant(pc_offset, constant, CHECK); 1031 pd_patch_MetaspaceConstant(pc_offset, constant, CHECK);
991 } else { 1032 } else {
992 JVMCI_ERROR("unknown constant type in data patch: %s", constant->klass()->signature_name()); 1033 JVMCI_ERROR("unknown constant type in data patch: %s", constant->klass()->signature_name());