Skip to content

Commit

Permalink
8262912: ciReplay: replay does not simulate unresolved classes
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, dlong
  • Loading branch information
chhagedorn committed Oct 15, 2021
1 parent 322b130 commit 4cb7124
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/hotspot/share/ci/ciEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,15 @@ ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool,
}

// It is known to be accessible, since it was found in the constant pool.
ciKlass* ciKlass = get_klass(klass);
is_accessible = true;
return get_klass(klass);
#ifndef PRODUCT
if (ReplayCompiles && ciKlass == _unloaded_ciinstance_klass) {
// Klass was unresolved at replay dump time and therefore not accessible.
is_accessible = false;
}
#endif
return ciKlass;
}

// ------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions src/hotspot/share/ci/ciEnv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "ci/ciClassList.hpp"
#include "ci/ciObjectFactory.hpp"
#include "ci/ciReplay.hpp"
#include "classfile/vmClassMacros.hpp"
#include "code/debugInfoRec.hpp"
#include "code/dependencies.hpp"
Expand Down Expand Up @@ -187,6 +188,15 @@ class ciEnv : StackObj {
if (o == NULL) {
return NULL;
} else {
#ifndef PRODUCT
if (ReplayCompiles && o->is_klass()) {
Klass* k = (Klass*)o;
if (k->is_instance_klass() && ciReplay::is_klass_unresolved((InstanceKlass*)k)) {
// Klass was unresolved at replay dump time. Simulate this case.
return ciEnv::_unloaded_ciinstance_klass;
}
}
#endif
return _factory->get_metadata(o);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/ci/ciInstanceKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ciInstanceKlass : public ciKlass {
friend class ciExceptionHandler;
friend class ciMethod;
friend class ciField;
friend class ciReplay;

private:
enum SubklassValue { subklass_unknown, subklass_false, subklass_true };
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/ci/ciObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
if (o->is_klass()) {
Klass* k = (Klass*)o;
if (k->is_instance_klass()) {
assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
return new (arena()) ciInstanceKlass(k);
} else if (k->is_objArray_klass()) {
return new (arena()) ciObjArrayKlass(k);
Expand Down
71 changes: 62 additions & 9 deletions src/hotspot/share/ci/ciReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "runtime/fieldDescriptor.inline.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/jniHandles.inline.hpp"
#include "runtime/java.hpp"
#include "utilities/copy.hpp"
#include "utilities/macros.hpp"
Expand Down Expand Up @@ -90,6 +91,11 @@ typedef struct _ciMethodRecord {
int _backedge_counter;
} ciMethodRecord;

typedef struct _ciInstanceKlassRecord {
const InstanceKlass* _klass;
jobject _java_mirror; // Global handle to java mirror to prevent unloading
} ciInstanceKlassRecord;

typedef struct _ciInlineRecord {
const char* _klass_name;
const char* _method_name;
Expand All @@ -111,6 +117,7 @@ class CompileReplay : public StackObj {

GrowableArray<ciMethodRecord*> _ci_method_records;
GrowableArray<ciMethodDataRecord*> _ci_method_data_records;
GrowableArray<ciInstanceKlassRecord*> _ci_instance_klass_records;

// Use pointer because we may need to return inline records
// without destroying them.
Expand Down Expand Up @@ -882,7 +889,7 @@ class CompileReplay : public StackObj {
// constant pool is the same length as 'length' and make sure the
// constant pool tags are in the same state.
void process_ciInstanceKlass(TRAPS) {
InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
InstanceKlass* k = (InstanceKlass*)parse_klass(CHECK);
if (k == NULL) {
return;
}
Expand All @@ -905,6 +912,7 @@ class CompileReplay : public StackObj {
} else if (is_linked) {
k->link_class(CHECK);
}
new_ciInstanceKlass(k);
ConstantPool* cp = k->constants();
if (length != cp->length()) {
report_error("constant pool length mismatch: wrong class files?");
Expand Down Expand Up @@ -951,10 +959,10 @@ class CompileReplay : public StackObj {
break;

case JVM_CONSTANT_Class:
if (tag == JVM_CONSTANT_Class) {
} else if (tag == JVM_CONSTANT_UnresolvedClass) {
tty->print_cr("Warning: entry was unresolved in the replay data");
} else {
if (tag == JVM_CONSTANT_UnresolvedClass) {
Klass* k = cp->klass_at(i, CHECK);
tty->print_cr("Warning: entry was unresolved in the replay data: %s", k->name()->as_utf8());
} else if (tag != JVM_CONSTANT_Class) {
report_error("Unexpected tag");
return;
}
Expand Down Expand Up @@ -1132,6 +1140,28 @@ class CompileReplay : public StackObj {
return NULL;
}

// Create and initialize a record for a ciInstanceKlass which was present at replay dump time.
void new_ciInstanceKlass(const InstanceKlass* klass) {
ciInstanceKlassRecord* rec = NEW_RESOURCE_OBJ(ciInstanceKlassRecord);
rec->_klass = klass;
oop java_mirror = klass->java_mirror();
Handle h_java_mirror(_thread, java_mirror);
rec->_java_mirror = JNIHandles::make_global(h_java_mirror);
_ci_instance_klass_records.append(rec);
}

// Check if a ciInstanceKlass was present at replay dump time for a klass.
ciInstanceKlassRecord* find_ciInstanceKlass(const InstanceKlass* klass) {
for (int i = 0; i < _ci_instance_klass_records.length(); i++) {
ciInstanceKlassRecord* rec = _ci_instance_klass_records.at(i);
if (klass == rec->_klass) {
// ciInstanceKlass for this klass was resolved.
return rec;
}
}
return NULL;
}

// Create and initialize a record for a ciMethodData
ciMethodDataRecord* new_ciMethodData(Method* method) {
ciMethodDataRecord* rec = NEW_RESOURCE_OBJ(ciMethodDataRecord);
Expand Down Expand Up @@ -1265,6 +1295,10 @@ void ciReplay::replay(TRAPS) {
vm_exit(exit_code);
}

bool ciReplay::no_replay_state() {
return replay_state == NULL;
}

void* ciReplay::load_inline_data(ciMethod* method, int entry_bci, int comp_level) {
if (FLAG_IS_DEFAULT(InlineDataFile)) {
tty->print_cr("ERROR: no inline replay data file specified (use -XX:InlineDataFile=inline_pid12345.txt).");
Expand Down Expand Up @@ -1336,7 +1370,7 @@ int ciReplay::replay_impl(TRAPS) {
}

void ciReplay::initialize(ciMethodData* m) {
if (replay_state == NULL) {
if (no_replay_state()) {
return;
}

Expand Down Expand Up @@ -1390,7 +1424,7 @@ void ciReplay::initialize(ciMethodData* m) {


bool ciReplay::should_not_inline(ciMethod* method) {
if (replay_state == NULL) {
if (no_replay_state()) {
return false;
}
VM_ENTRY_MARK;
Expand Down Expand Up @@ -1427,7 +1461,7 @@ bool ciReplay::should_not_inline(void* data, ciMethod* method, int bci, int inli
}

void ciReplay::initialize(ciMethod* m) {
if (replay_state == NULL) {
if (no_replay_state()) {
return;
}

Expand Down Expand Up @@ -1456,8 +1490,17 @@ void ciReplay::initialize(ciMethod* m) {
}
}

void ciReplay::initialize(ciInstanceKlass* ci_ik, InstanceKlass* ik) {
assert(!no_replay_state(), "must have replay state");

ASSERT_IN_VM;
ciInstanceKlassRecord* rec = replay_state->find_ciInstanceKlass(ik);
assert(rec != NULL, "ciInstanceKlass must be whitelisted");
ci_ik->_java_mirror = CURRENT_ENV->get_instance(JNIHandles::resolve(rec->_java_mirror));
}

bool ciReplay::is_loaded(Method* method) {
if (replay_state == NULL) {
if (no_replay_state()) {
return true;
}

Expand All @@ -1467,6 +1510,16 @@ bool ciReplay::is_loaded(Method* method) {
ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
return rec != NULL;
}

bool ciReplay::is_klass_unresolved(const InstanceKlass* klass) {
if (no_replay_state()) {
return false;
}

// Check if klass is found on whitelist.
ciInstanceKlassRecord* rec = replay_state->find_ciInstanceKlass(klass);
return rec == NULL;
}
#endif // PRODUCT

oop ciReplay::obj_field(oop obj, Symbol* name) {
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/ci/ciReplay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ciReplay {
public:
// Replay specified compilation and exit VM.
static void replay(TRAPS);
static bool no_replay_state();
// Load inlining decisions from file and use them
// during compilation of specified method.
static void* load_inline_data(ciMethod* method, int entry_bci, int comp_level);
Expand All @@ -114,7 +115,9 @@ class ciReplay {
// replay file when replaying compiles.
static void initialize(ciMethodData* method);
static void initialize(ciMethod* method);
static void initialize(ciInstanceKlass* ciKlass, InstanceKlass* ik);

static bool is_klass_unresolved(const InstanceKlass* klass);
static bool is_loaded(Method* method);

static bool should_not_inline(ciMethod* method);
Expand Down
14 changes: 9 additions & 5 deletions test/hotspot/jtreg/compiler/ciReplay/CiReplayBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void runTest(boolean needCoreDump, String... args) {

public abstract void testAction();

private static void remove(String item) {
public static void remove(String item) {
File toDelete = new File(item);
toDelete.delete();
if (Platform.isWindows()) {
Expand Down Expand Up @@ -164,14 +164,14 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH);
if (needCoreDump) {
// CiReplayBase$TestMain needs to be quoted because of shell eval
options.add("-XX:CompileOnly='" + TestMain.class.getName() + "::test'");
options.add("'" + TestMain.class.getName() + "'");
options.add("-XX:CompileOnly='" + getTestClass() + "::test'");
options.add("'" + getTestClass() + "'");
crashOut = ProcessTools.executeProcess(
CoreUtils.addCoreUlimitCommand(
ProcessTools.createTestJvm(options.toArray(new String[0]))));
} else {
options.add("-XX:CompileOnly=" + TestMain.class.getName() + "::test");
options.add(TestMain.class.getName());
options.add("-XX:CompileOnly=" + getTestClass() + "::test");
options.add(getTestClass());
crashOut = ProcessTools.executeProcess(ProcessTools.createTestJvm(options));
}
crashOutputString = crashOut.getOutput();
Expand All @@ -194,6 +194,10 @@ public boolean generateReplay(boolean needCoreDump, String... vmopts) {
return true;
}

public String getTestClass() {
return TestMain.class.getName();
}

public void commonTests() {
positiveTest();
if (Platform.isTieredSupported()) {
Expand Down
Loading

0 comments on commit 4cb7124

Please sign in to comment.