Skip to content

Commit c5c8c06

Browse files
author
Vladimir Ivanov
committed
8279822: CI: Constant pool entries in error state are not supported
Reviewed-by: kvn, thartmann
1 parent f823bed commit c5c8c06

File tree

10 files changed

+403
-90
lines changed

10 files changed

+403
-90
lines changed

src/hotspot/share/ci/bcEscapeAnalyzer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ void BCEscapeAnalyzer::iterate_one_block(ciBlock *blk, StateInfo &state, Growabl
416416
// Avoid calling get_constant() which will try to allocate
417417
// unloaded constant. We need only constant's type.
418418
int index = s.get_constant_pool_index();
419-
constantTag tag = s.get_constant_pool_tag(index);
420-
if (tag.is_long() || tag.is_double()) {
419+
BasicType con_bt = s.get_basic_type_for_constant_at(index);
420+
if (con_bt == T_LONG || con_bt == T_DOUBLE) {
421421
// Only longs and doubles use 2 stack slots.
422422
state.lpush();
423-
} else if (tag.basic_type() == T_OBJECT) {
423+
} else if (con_bt == T_OBJECT) {
424424
state.apush(unknown_obj);
425425
} else {
426426
state.spush();

src/hotspot/share/ci/ciConstant.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ class ciConstant {
127127
bool is_valid() const {
128128
return basic_type() != T_ILLEGAL;
129129
}
130+
131+
bool is_loaded() const {
132+
if (is_valid()) {
133+
if (is_reference_type(basic_type())) {
134+
return as_object()->is_loaded();
135+
} else {
136+
return true;
137+
}
138+
}
139+
return false;
140+
}
130141
// Debugging output
131142
void print();
132143
};

src/hotspot/share/ci/ciEnv.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,6 @@ ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
503503
domain = Handle(current, accessing_klass->protection_domain());
504504
}
505505

506-
// setup up the proper type to return on OOM
507-
ciKlass* fail_type;
508-
if (sym->char_at(0) == JVM_SIGNATURE_ARRAY) {
509-
fail_type = _unloaded_ciobjarrayklass;
510-
} else {
511-
fail_type = _unloaded_ciinstance_klass;
512-
}
513506
Klass* found_klass;
514507
{
515508
ttyUnlocker ttyul; // release tty lock to avoid ordering problems
@@ -591,15 +584,14 @@ ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
591584
int index,
592585
bool& is_accessible,
593586
ciInstanceKlass* accessor) {
594-
EXCEPTION_CONTEXT;
595587
Klass* klass = NULL;
596588
Symbol* klass_name = NULL;
597589

598590
if (cpool->tag_at(index).is_symbol()) {
599591
klass_name = cpool->symbol_at(index);
600592
} else {
601593
// Check if it's resolved if it's not a symbol constant pool entry.
602-
klass = ConstantPool::klass_at_if_loaded(cpool, index);
594+
klass = ConstantPool::klass_at_if_loaded(cpool, index);
603595
// Try to look it up by name.
604596
if (klass == NULL) {
605597
klass_name = cpool->klass_name_at(index);
@@ -666,7 +658,6 @@ ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
666658
int pool_index, int cache_index,
667659
ciInstanceKlass* accessor) {
668660
bool ignore_will_link;
669-
EXCEPTION_CONTEXT;
670661
int index = pool_index;
671662
if (cache_index >= 0) {
672663
assert(index < 0, "only one kind of index at a time");
@@ -677,12 +668,14 @@ ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
677668
return ciConstant(T_OBJECT, get_object(NULL));
678669
}
679670
BasicType bt = T_OBJECT;
680-
if (cpool->tag_at(index).is_dynamic_constant())
671+
if (cpool->tag_at(index).is_dynamic_constant()) {
681672
bt = Signature::basic_type(cpool->uncached_signature_ref_at(index));
682-
if (is_reference_type(bt)) {
683-
} else {
673+
}
674+
if (!is_reference_type(bt)) {
684675
// we have to unbox the primitive value
685-
if (!is_java_primitive(bt)) return ciConstant();
676+
if (!is_java_primitive(bt)) {
677+
return ciConstant();
678+
}
686679
jvalue value;
687680
BasicType bt2 = java_lang_boxing_object::get_value(obj, &value);
688681
assert(bt2 == bt, "");
@@ -717,6 +710,7 @@ ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
717710
} else if (tag.is_double()) {
718711
return ciConstant((jdouble)cpool->double_at(index));
719712
} else if (tag.is_string()) {
713+
EXCEPTION_CONTEXT;
720714
oop string = NULL;
721715
assert(cache_index >= 0, "should have a cache index");
722716
string = cpool->string_at(index, cache_index, THREAD);
@@ -733,24 +727,18 @@ ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
733727
return ciConstant(T_OBJECT, constant);
734728
}
735729
} else if (tag.is_unresolved_klass_in_error()) {
736-
return ciConstant();
730+
return ciConstant(T_OBJECT, get_unloaded_klass_mirror(NULL));
737731
} else if (tag.is_klass() || tag.is_unresolved_klass()) {
738-
// 4881222: allow ldc to take a class type
739732
ciKlass* klass = get_klass_by_index_impl(cpool, index, ignore_will_link, accessor);
740-
if (HAS_PENDING_EXCEPTION) {
741-
CLEAR_PENDING_EXCEPTION;
742-
record_out_of_memory_failure();
743-
return ciConstant();
744-
}
745733
assert (klass->is_instance_klass() || klass->is_array_klass(),
746734
"must be an instance or array klass ");
747735
return ciConstant(T_OBJECT, klass->java_mirror());
748-
} else if (tag.is_method_type()) {
736+
} else if (tag.is_method_type() || tag.is_method_type_in_error()) {
749737
// must execute Java code to link this CP entry into cache[i].f1
750738
ciSymbol* signature = get_symbol(cpool->method_type_signature_at(index));
751739
ciObject* ciobj = get_unloaded_method_type_constant(signature);
752740
return ciConstant(T_OBJECT, ciobj);
753-
} else if (tag.is_method_handle()) {
741+
} else if (tag.is_method_handle() || tag.is_method_handle_in_error()) {
754742
// must execute Java code to link this CP entry into cache[i].f1
755743
int ref_kind = cpool->method_handle_ref_kind_at(index);
756744
int callee_index = cpool->method_handle_klass_index_at(index);
@@ -759,10 +747,10 @@ ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool,
759747
ciSymbol* signature = get_symbol(cpool->method_handle_signature_ref_at(index));
760748
ciObject* ciobj = get_unloaded_method_handle_constant(callee, name, signature, ref_kind);
761749
return ciConstant(T_OBJECT, ciobj);
762-
} else if (tag.is_dynamic_constant()) {
763-
return ciConstant();
750+
} else if (tag.is_dynamic_constant() || tag.is_dynamic_constant_in_error()) {
751+
return ciConstant(); // not supported
764752
} else {
765-
ShouldNotReachHere();
753+
assert(false, "unknown tag: %d (%s)", tag.value(), tag.internal_name());
766754
return ciConstant();
767755
}
768756
}

src/hotspot/share/ci/ciStreams.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,14 @@ constantTag ciBytecodeStream::get_constant_pool_tag(int index) const {
251251
return _method->get_Method()->constants()->constant_tag_at(index);
252252
}
253253

254+
// ------------------------------------------------------------------
255+
// ciBytecodeStream::get_basic_type_for_constant_at
256+
//
257+
BasicType ciBytecodeStream::get_basic_type_for_constant_at(int index) const {
258+
VM_ENTRY_MARK;
259+
return _method->get_Method()->constants()->basic_type_for_constant_at(index);
260+
}
261+
254262
// ------------------------------------------------------------------
255263
// ciBytecodeStream::get_field_index
256264
//

src/hotspot/share/ci/ciStreams.hpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ciBytecodeStream : StackObj {
140140

141141
bool is_wide() const { return ( _pc == _was_wide ); }
142142

143-
// Does this instruction contain an index which refes into the CP cache?
143+
// Does this instruction contain an index which refers into the CP cache?
144144
bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
145145

146146
int get_index_u1() const {
@@ -226,18 +226,27 @@ class ciBytecodeStream : StackObj {
226226
// constant. Do not attempt to resolve it, since that would require
227227
// execution of Java code. If it is not resolved, return an unloaded
228228
// object (ciConstant.as_object()->is_loaded() == false).
229-
ciConstant get_constant();
229+
ciConstant get_constant();
230230
constantTag get_constant_pool_tag(int index) const;
231+
BasicType get_basic_type_for_constant_at(int index) const;
231232

232233
// True if the klass-using bytecode points to an unresolved klass
233234
bool is_unresolved_klass() const {
234235
constantTag tag = get_constant_pool_tag(get_klass_index());
235236
return tag.is_unresolved_klass();
236237
}
237238

238-
bool is_unresolved_klass_in_error() const {
239-
constantTag tag = get_constant_pool_tag(get_klass_index());
240-
return tag.is_unresolved_klass_in_error();
239+
bool is_in_error() const {
240+
assert(cur_bc() == Bytecodes::_ldc ||
241+
cur_bc() == Bytecodes::_ldc_w ||
242+
cur_bc() == Bytecodes::_ldc2_w, "not supported: %s", Bytecodes::name(cur_bc()));
243+
244+
int index = get_constant_pool_index();
245+
constantTag tag = get_constant_pool_tag(index);
246+
return tag.is_unresolved_klass_in_error() ||
247+
tag.is_method_handle_in_error() ||
248+
tag.is_method_type_in_error() ||
249+
tag.is_dynamic_constant_in_error();
241250
}
242251

243252
// If this bytecode is one of get_field, get_static, put_field,

src/hotspot/share/ci/ciTypeFlow.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
720720
// ------------------------------------------------------------------
721721
// ciTypeFlow::StateVector::do_ldc
722722
void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
723+
if (str->is_in_error()) {
724+
trap(str, NULL, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
725+
Deoptimization::Action_none));
726+
return;
727+
}
723728
ciConstant con = str->get_constant();
724729
if (con.is_valid()) {
725730
BasicType basic_type = con.basic_type();
@@ -735,14 +740,10 @@ void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
735740
push_translate(ciType::make(basic_type));
736741
}
737742
} else {
738-
if (str->is_unresolved_klass_in_error()) {
739-
trap(str, NULL, Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
740-
Deoptimization::Action_none));
741-
} else {
742-
// OutOfMemoryError in the CI while loading constant
743-
push_null();
744-
outer()->record_failure("ldc did not link");
745-
}
743+
// OutOfMemoryError in the CI while loading constant.
744+
// Unresolved condy also lands here (not yet supported).
745+
push_null();
746+
outer()->record_failure("ldc did not link");
746747
}
747748
}
748749

@@ -2173,7 +2174,7 @@ bool ciTypeFlow::can_trap(ciBytecodeStream& str) {
21732174
case Bytecodes::_ldc:
21742175
case Bytecodes::_ldc_w:
21752176
case Bytecodes::_ldc2_w:
2176-
return str.is_unresolved_klass_in_error();
2177+
return str.is_in_error();
21772178

21782179
case Bytecodes::_aload_0:
21792180
// These bytecodes can trap for rewriting. We need to assume that

src/hotspot/share/oops/constantPool.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,9 @@ void ConstantPool::save_and_throw_exception(const constantPoolHandle& this_cp, i
885885

886886
constantTag ConstantPool::constant_tag_at(int which) {
887887
constantTag tag = tag_at(which);
888-
if (tag.is_dynamic_constant() ||
889-
tag.is_dynamic_constant_in_error()) {
888+
if (tag.is_dynamic_constant()) {
890889
BasicType bt = basic_type_for_constant_at(which);
891-
// dynamic constant could return an array, treat as object
892-
return constantTag::ofBasicType(is_reference_type(bt) ? T_OBJECT : bt);
890+
return constantTag(constantTag::type2tag(bt));
893891
}
894892
return tag;
895893
}
@@ -976,7 +974,6 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
976974
switch (tag.value()) {
977975

978976
case JVM_CONSTANT_UnresolvedClass:
979-
case JVM_CONSTANT_UnresolvedClassInError:
980977
case JVM_CONSTANT_Class:
981978
{
982979
assert(cache_index == _no_index_sentinel, "should not have been set");
@@ -1044,14 +1041,6 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
10441041
result_oop = string_at_impl(this_cp, index, cache_index, CHECK_NULL);
10451042
break;
10461043

1047-
case JVM_CONSTANT_DynamicInError:
1048-
case JVM_CONSTANT_MethodHandleInError:
1049-
case JVM_CONSTANT_MethodTypeInError:
1050-
{
1051-
throw_resolution_error(this_cp, index, CHECK_NULL);
1052-
break;
1053-
}
1054-
10551044
case JVM_CONSTANT_MethodHandle:
10561045
{
10571046
int ref_kind = this_cp->method_handle_ref_kind_at(index);
@@ -1065,11 +1054,14 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
10651054
callee_index, name->as_C_string(), signature->as_C_string());
10661055
}
10671056

1068-
Klass* callee = klass_at_impl(this_cp, callee_index, CHECK_NULL);
1057+
Klass* callee = klass_at_impl(this_cp, callee_index, THREAD);
1058+
if (HAS_PENDING_EXCEPTION) {
1059+
save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
1060+
}
10691061

10701062
// Check constant pool method consistency
10711063
if ((callee->is_interface() && m_tag.is_method()) ||
1072-
((!callee->is_interface() && m_tag.is_interface_method()))) {
1064+
(!callee->is_interface() && m_tag.is_interface_method())) {
10731065
ResourceMark rm(THREAD);
10741066
stringStream ss;
10751067
ss.print("Inconsistent constant pool data in classfile for class %s. "
@@ -1081,17 +1073,18 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
10811073
index,
10821074
callee->is_interface() ? "CONSTANT_MethodRef" : "CONSTANT_InterfaceMethodRef",
10831075
callee->is_interface() ? "CONSTANT_InterfaceMethodRef" : "CONSTANT_MethodRef");
1084-
THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
1076+
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IncompatibleClassChangeError(), "%s", ss.as_string());
1077+
save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
10851078
}
10861079

10871080
Klass* klass = this_cp->pool_holder();
10881081
Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
10891082
callee, name, signature,
10901083
THREAD);
1091-
result_oop = value();
10921084
if (HAS_PENDING_EXCEPTION) {
10931085
save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
10941086
}
1087+
result_oop = value();
10951088
break;
10961089
}
10971090

@@ -1136,10 +1129,15 @@ oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
11361129
result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL);
11371130
break;
11381131

1132+
case JVM_CONSTANT_UnresolvedClassInError:
1133+
case JVM_CONSTANT_DynamicInError:
1134+
case JVM_CONSTANT_MethodHandleInError:
1135+
case JVM_CONSTANT_MethodTypeInError:
1136+
throw_resolution_error(this_cp, index, CHECK_NULL);
1137+
break;
1138+
11391139
default:
1140-
DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
1141-
this_cp(), index, cache_index, tag.value()));
1142-
assert(false, "unexpected constant tag");
1140+
fatal("unexpected constant tag at CP %p[%d/%d] = %d", this_cp(), index, cache_index, tag.value());
11431141
break;
11441142
}
11451143

src/hotspot/share/opto/parse2.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,33 +1865,35 @@ void Parse::do_one_bytecode() {
18651865
case Bytecodes::_bipush: push(intcon(iter().get_constant_u1())); break;
18661866
case Bytecodes::_sipush: push(intcon(iter().get_constant_u2())); break;
18671867
case Bytecodes::_aconst_null: push(null()); break;
1868+
18681869
case Bytecodes::_ldc:
18691870
case Bytecodes::_ldc_w:
1870-
case Bytecodes::_ldc2_w:
1871-
// If the constant is unresolved, run this BC once in the interpreter.
1872-
{
1873-
ciConstant constant = iter().get_constant();
1874-
if (!constant.is_valid() ||
1875-
(constant.basic_type() == T_OBJECT &&
1876-
!constant.as_object()->is_loaded())) {
1877-
int index = iter().get_constant_pool_index();
1878-
constantTag tag = iter().get_constant_pool_tag(index);
1879-
uncommon_trap(Deoptimization::make_trap_request
1880-
(Deoptimization::Reason_unloaded,
1881-
Deoptimization::Action_reinterpret,
1882-
index),
1883-
NULL, tag.internal_name());
1884-
break;
1885-
}
1871+
case Bytecodes::_ldc2_w: {
1872+
ciConstant constant = iter().get_constant();
1873+
if (constant.is_loaded()) {
18861874
assert(constant.basic_type() != T_OBJECT || constant.as_object()->is_instance(),
18871875
"must be java_mirror of klass");
18881876
const Type* con_type = Type::make_from_constant(constant);
18891877
if (con_type != NULL) {
18901878
push_node(con_type->basic_type(), makecon(con_type));
18911879
}
1892-
}
1880+
} else {
1881+
// If the constant is unresolved or in error state, run this BC in the interpreter.
1882+
if (iter().is_in_error()) {
1883+
uncommon_trap(Deoptimization::make_trap_request(Deoptimization::Reason_unhandled,
1884+
Deoptimization::Action_none),
1885+
NULL, "constant in error state", true /* must_throw */);
18931886

1887+
} else {
1888+
int index = iter().get_constant_pool_index();
1889+
uncommon_trap(Deoptimization::make_trap_request(Deoptimization::Reason_unloaded,
1890+
Deoptimization::Action_reinterpret,
1891+
index),
1892+
NULL, "unresolved constant", false /* must_throw */);
1893+
}
1894+
}
18941895
break;
1896+
}
18951897

18961898
case Bytecodes::_aload_0:
18971899
push( local(0) );

0 commit comments

Comments
 (0)