提交 d7a277f6 编写于 作者: K kvn

8028468: Add inlining information into ciReplay

Summary: Allow dump and replay inlining for specified method during a program execution.
Reviewed-by: roland, twisti
上级 bdfb985c
......@@ -95,9 +95,15 @@ public class ciEnv extends VMObject {
int entryBci = task.osrBci();
int compLevel = task.compLevel();
Klass holder = method.getMethodHolder();
out.println("compile " + holder.getName().asString() + " " +
OopUtilities.escapeString(method.getName().asString()) + " " +
method.getSignature().asString() + " " +
entryBci + " " + compLevel);
out.print("compile " + holder.getName().asString() + " " +
OopUtilities.escapeString(method.getName().asString()) + " " +
method.getSignature().asString() + " " +
entryBci + " " + compLevel);
Compile compiler = compilerData();
if (compiler != null) {
// Dump inlining data.
compiler.dumpInlineData(out);
}
out.println();
}
}
......@@ -25,6 +25,7 @@
package sun.jvm.hotspot.opto;
import java.util.*;
import java.io.PrintStream;
import sun.jvm.hotspot.ci.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
......@@ -92,4 +93,13 @@ public class Compile extends VMObject {
}
return null;
}
public void dumpInlineData(PrintStream out) {
InlineTree inlTree = ilt();
if (inlTree != null) {
out.print(" inline " + inlTree.count());
inlTree.dumpReplayData(out);
}
}
}
......@@ -87,6 +87,11 @@ public class InlineTree extends VMObject {
return GrowableArray.create(addr, inlineTreeConstructor);
}
public int inlineLevel() {
JVMState jvms = callerJvms();
return (jvms != null) ? jvms.depth() : 0;
}
public void printImpl(PrintStream st, int indent) {
for (int i = 0; i < indent; i++) st.print(" ");
st.printf(" @ %d ", callerBci());
......@@ -101,4 +106,28 @@ public class InlineTree extends VMObject {
public void print(PrintStream st) {
printImpl(st, 2);
}
// Count number of nodes in this subtree
public int count() {
int result = 1;
GrowableArray<InlineTree> subt = subtrees();
for (int i = 0 ; i < subt.length(); i++) {
result += subt.at(i).count();
}
return result;
}
public void dumpReplayData(PrintStream out) {
out.printf(" %d %d ", inlineLevel(), callerBci());
Method method = (Method)method().getMetadata();
Klass holder = method.getMethodHolder();
out.print(holder.getName().asString() + " " +
OopUtilities.escapeString(method.getName().asString()) + " " +
method.getSignature().asString());
GrowableArray<InlineTree> subt = subtrees();
for (int i = 0 ; i < subt.length(); i++) {
subt.at(i).dumpReplayData(out);
}
}
}
......@@ -88,6 +88,10 @@ public class JVMState extends VMObject {
return (int)bciField.getValue(getAddress());
}
public int depth() {
return (int)depthField.getValue(getAddress());
}
public JVMState caller() {
return create(callerField.getValue(getAddress()));
}
......
......@@ -259,6 +259,9 @@ class Compilation: public StackObj {
}
ciKlass* cha_exact_type(ciType* type);
// Dump inlining replay data to the stream.
void dump_inline_data(outputStream* out) { /* do nothing now */ }
};
......
......@@ -1147,6 +1147,33 @@ ciInstance* ciEnv::unloaded_ciinstance() {
// Don't change thread state and acquire any locks.
// Safe to call from VM error reporter.
void ciEnv::dump_compile_data(outputStream* out) {
CompileTask* task = this->task();
Method* method = task->method();
int entry_bci = task->osr_bci();
int comp_level = task->comp_level();
out->print("compile %s %s %s %d %d",
method->klass_name()->as_quoted_ascii(),
method->name()->as_quoted_ascii(),
method->signature()->as_quoted_ascii(),
entry_bci, comp_level);
if (compiler_data() != NULL) {
if (is_c2_compile(comp_level)) { // C2 or Shark
#ifdef COMPILER2
// Dump C2 inlining data.
((Compile*)compiler_data())->dump_inline_data(out);
#endif
} else if (is_c1_compile(comp_level)) { // C1
#ifdef COMPILER1
// Dump C1 inlining data.
((Compilation*)compiler_data())->dump_inline_data(out);
#endif
}
}
out->cr();
}
void ciEnv::dump_replay_data_unsafe(outputStream* out) {
ResourceMark rm;
#if INCLUDE_JVMTI
......@@ -1160,16 +1187,7 @@ void ciEnv::dump_replay_data_unsafe(outputStream* out) {
for (int i = 0; i < objects->length(); i++) {
objects->at(i)->dump_replay_data(out);
}
CompileTask* task = this->task();
Method* method = task->method();
int entry_bci = task->osr_bci();
int comp_level = task->comp_level();
// Klass holder = method->method_holder();
out->print_cr("compile %s %s %s %d %d",
method->klass_name()->as_quoted_ascii(),
method->name()->as_quoted_ascii(),
method->signature()->as_quoted_ascii(),
entry_bci, comp_level);
dump_compile_data(out);
out->flush();
}
......@@ -1179,3 +1197,45 @@ void ciEnv::dump_replay_data(outputStream* out) {
dump_replay_data_unsafe(out);
)
}
void ciEnv::dump_replay_data(int compile_id) {
static char buffer[O_BUFLEN];
int ret = jio_snprintf(buffer, O_BUFLEN, "replay_pid%p_compid%d.log", os::current_process_id(), compile_id);
if (ret > 0) {
int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd != -1) {
FILE* replay_data_file = os::open(fd, "w");
if (replay_data_file != NULL) {
fileStream replay_data_stream(replay_data_file, /*need_close=*/true);
dump_replay_data(&replay_data_stream);
tty->print("# Compiler replay data is saved as: ");
tty->print_cr(buffer);
} else {
tty->print_cr("# Can't open file to dump replay data.");
}
}
}
}
void ciEnv::dump_inline_data(int compile_id) {
static char buffer[O_BUFLEN];
int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id);
if (ret > 0) {
int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd != -1) {
FILE* inline_data_file = os::open(fd, "w");
if (inline_data_file != NULL) {
fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
GUARDED_VM_ENTRY(
MutexLocker ml(Compile_lock);
dump_compile_data(&replay_data_stream);
)
replay_data_stream.flush();
tty->print("# Compiler inline data is saved as: ");
tty->print_cr(buffer);
} else {
tty->print_cr("# Can't open file to dump inline data.");
}
}
}
}
......@@ -451,8 +451,11 @@ public:
void metadata_do(void f(Metadata*)) { _factory->metadata_do(f); }
// Dump the compilation replay data for the ciEnv to the stream.
void dump_replay_data(int compile_id);
void dump_inline_data(int compile_id);
void dump_replay_data(outputStream* out);
void dump_replay_data_unsafe(outputStream* out);
void dump_compile_data(outputStream* out);
};
#endif // SHARE_VM_CI_CIENV_HPP
......@@ -1357,15 +1357,21 @@ ciMethodBlocks *ciMethod::get_method_blocks() {
#undef FETCH_FLAG_FROM_VM
void ciMethod::dump_name_as_ascii(outputStream* st) {
Method* method = get_Method();
st->print("%s %s %s",
method->klass_name()->as_quoted_ascii(),
method->name()->as_quoted_ascii(),
method->signature()->as_quoted_ascii());
}
void ciMethod::dump_replay_data(outputStream* st) {
ResourceMark rm;
Method* method = get_Method();
MethodCounters* mcs = method->method_counters();
Klass* holder = method->method_holder();
st->print_cr("ciMethod %s %s %s %d %d %d %d %d",
holder->name()->as_quoted_ascii(),
method->name()->as_quoted_ascii(),
method->signature()->as_quoted_ascii(),
st->print("ciMethod ");
dump_name_as_ascii(st);
st->print_cr(" %d %d %d %d %d",
mcs == NULL ? 0 : mcs->invocation_counter()->raw_counter(),
mcs == NULL ? 0 : mcs->backedge_counter()->raw_counter(),
interpreter_invocation_count(),
......
......@@ -310,10 +310,13 @@ class ciMethod : public ciMetadata {
bool is_accessor () const;
bool is_initializer () const;
bool can_be_statically_bound() const { return _can_be_statically_bound; }
void dump_replay_data(outputStream* st);
bool is_boxing_method() const;
bool is_unboxing_method() const;
// Replay data methods
void dump_name_as_ascii(outputStream* st);
void dump_replay_data(outputStream* st);
// Print the bytecodes of this method.
void print_codes_on(outputStream* st);
void print_codes() {
......
......@@ -24,6 +24,8 @@
#include "precompiled.hpp"
#include "ci/ciMethodData.hpp"
#include "ci/ciReplay.hpp"
#include "ci/ciSymbol.hpp"
#include "ci/ciKlass.hpp"
#include "ci/ciUtilities.hpp"
#include "compiler/compileBroker.hpp"
#include "memory/allocation.inline.hpp"
......@@ -37,74 +39,107 @@
// ciReplay
typedef struct _ciMethodDataRecord {
const char* klass;
const char* method;
const char* signature;
int state;
int current_mileage;
intptr_t* data;
int data_length;
char* orig_data;
int orig_data_length;
int oops_length;
jobject* oops_handles;
int* oops_offsets;
const char* _klass_name;
const char* _method_name;
const char* _signature;
int _state;
int _current_mileage;
intptr_t* _data;
char* _orig_data;
jobject* _oops_handles;
int* _oops_offsets;
int _data_length;
int _orig_data_length;
int _oops_length;
} ciMethodDataRecord;
typedef struct _ciMethodRecord {
const char* klass;
const char* method;
const char* signature;
int instructions_size;
int interpreter_invocation_count;
int interpreter_throwout_count;
int invocation_counter;
int backedge_counter;
const char* _klass_name;
const char* _method_name;
const char* _signature;
int _instructions_size;
int _interpreter_invocation_count;
int _interpreter_throwout_count;
int _invocation_counter;
int _backedge_counter;
} ciMethodRecord;
class CompileReplay;
typedef struct _ciInlineRecord {
const char* _klass_name;
const char* _method_name;
const char* _signature;
int _inline_depth;
int _inline_bci;
} ciInlineRecord;
class CompileReplay;
static CompileReplay* replay_state;
class CompileReplay : public StackObj {
private:
FILE* stream;
Thread* thread;
Handle protection_domain;
Handle loader;
FILE* _stream;
Thread* _thread;
Handle _protection_domain;
Handle _loader;
GrowableArray<ciMethodRecord*> _ci_method_records;
GrowableArray<ciMethodDataRecord*> _ci_method_data_records;
GrowableArray<ciMethodRecord*> ci_method_records;
GrowableArray<ciMethodDataRecord*> ci_method_data_records;
// Use pointer because we may need to return inline records
// without destroying them.
GrowableArray<ciInlineRecord*>* _ci_inline_records;
const char* _error_message;
char* bufptr;
char* buffer;
int buffer_length;
int buffer_end;
int line_no;
char* _bufptr;
char* _buffer;
int _buffer_length;
int _buffer_pos;
// "compile" data
ciKlass* _iklass;
Method* _imethod;
int _entry_bci;
int _comp_level;
public:
CompileReplay(const char* filename, TRAPS) {
thread = THREAD;
loader = Handle(thread, SystemDictionary::java_system_loader());
stream = fopen(filename, "rt");
if (stream == NULL) {
_thread = THREAD;
_loader = Handle(_thread, SystemDictionary::java_system_loader());
_protection_domain = Handle();
_stream = fopen(filename, "rt");
if (_stream == NULL) {
fprintf(stderr, "ERROR: Can't open replay file %s\n", filename);
}
buffer_length = 32;
buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
_ci_inline_records = NULL;
_error_message = NULL;
_buffer_length = 32;
_buffer = NEW_RESOURCE_ARRAY(char, _buffer_length);
_bufptr = _buffer;
_buffer_pos = 0;
_imethod = NULL;
_iklass = NULL;
_entry_bci = 0;
_comp_level = 0;
test();
}
~CompileReplay() {
if (stream != NULL) fclose(stream);
if (_stream != NULL) fclose(_stream);
}
void test() {
strcpy(buffer, "1 2 foo 4 bar 0x9 \"this is it\"");
bufptr = buffer;
strcpy(_buffer, "1 2 foo 4 bar 0x9 \"this is it\"");
_bufptr = _buffer;
assert(parse_int("test") == 1, "what");
assert(parse_int("test") == 2, "what");
assert(strcmp(parse_string(), "foo") == 0, "what");
......@@ -115,18 +150,18 @@ class CompileReplay : public StackObj {
}
bool had_error() {
return _error_message != NULL || thread->has_pending_exception();
return _error_message != NULL || _thread->has_pending_exception();
}
bool can_replay() {
return !(stream == NULL || had_error());
return !(_stream == NULL || had_error());
}
void report_error(const char* msg) {
_error_message = msg;
// Restore the buffer contents for error reporting
for (int i = 0; i < buffer_end; i++) {
if (buffer[i] == '\0') buffer[i] = ' ';
// Restore the _buffer contents for error reporting
for (int i = 0; i < _buffer_pos; i++) {
if (_buffer[i] == '\0') _buffer[i] = ' ';
}
}
......@@ -137,10 +172,10 @@ class CompileReplay : public StackObj {
int v = 0;
int read;
if (sscanf(bufptr, "%i%n", &v, &read) != 1) {
if (sscanf(_bufptr, "%i%n", &v, &read) != 1) {
report_error(label);
} else {
bufptr += read;
_bufptr += read;
}
return v;
}
......@@ -152,31 +187,31 @@ class CompileReplay : public StackObj {
intptr_t v = 0;
int read;
if (sscanf(bufptr, INTPTR_FORMAT "%n", &v, &read) != 1) {
if (sscanf(_bufptr, INTPTR_FORMAT "%n", &v, &read) != 1) {
report_error(label);
} else {
bufptr += read;
_bufptr += read;
}
return v;
}
void skip_ws() {
// Skip any leading whitespace
while (*bufptr == ' ' || *bufptr == '\t') {
bufptr++;
while (*_bufptr == ' ' || *_bufptr == '\t') {
_bufptr++;
}
}
char* scan_and_terminate(char delim) {
char* str = bufptr;
while (*bufptr != delim && *bufptr != '\0') {
bufptr++;
char* str = _bufptr;
while (*_bufptr != delim && *_bufptr != '\0') {
_bufptr++;
}
if (*bufptr != '\0') {
*bufptr++ = '\0';
if (*_bufptr != '\0') {
*_bufptr++ = '\0';
}
if (bufptr == str) {
if (_bufptr == str) {
// nothing here
return NULL;
}
......@@ -195,8 +230,8 @@ class CompileReplay : public StackObj {
skip_ws();
if (*bufptr == '"') {
bufptr++;
if (*_bufptr == '"') {
_bufptr++;
return scan_and_terminate('"');
} else {
return scan_and_terminate(' ');
......@@ -273,7 +308,12 @@ class CompileReplay : public StackObj {
const char* str = parse_escaped_string();
Symbol* klass_name = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
if (klass_name != NULL) {
Klass* k = SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, THREAD);
Klass* k = NULL;
if (_iklass != NULL) {
k = (Klass*)_iklass->find_klass(ciSymbol::make(klass_name->as_C_string()))->constant_encoding();
} else {
k = SystemDictionary::resolve_or_fail(klass_name, _loader, _protection_domain, true, THREAD);
}
if (HAS_PENDING_EXCEPTION) {
oop throwable = PENDING_EXCEPTION;
java_lang_Throwable::print(throwable, tty);
......@@ -289,7 +329,7 @@ class CompileReplay : public StackObj {
// Lookup a klass
Klass* resolve_klass(const char* klass, TRAPS) {
Symbol* klass_name = SymbolTable::lookup(klass, (int)strlen(klass), CHECK_NULL);
return SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, CHECK_NULL);
return SystemDictionary::resolve_or_fail(klass_name, _loader, _protection_domain, true, CHECK_NULL);
}
// Parse the standard tuple of <klass> <name> <signature>
......@@ -304,40 +344,45 @@ class CompileReplay : public StackObj {
return m;
}
// Process each line of the replay file executing each command until
// the file ends.
void process(TRAPS) {
line_no = 1;
int pos = 0;
int c = getc(stream);
int get_line(int c) {
while(c != EOF) {
if (pos + 1 >= buffer_length) {
int newl = buffer_length * 2;
char* newb = NEW_RESOURCE_ARRAY(char, newl);
memcpy(newb, buffer, pos);
buffer = newb;
buffer_length = newl;
if (_buffer_pos + 1 >= _buffer_length) {
int new_length = _buffer_length * 2;
// Next call will throw error in case of OOM.
_buffer = REALLOC_RESOURCE_ARRAY(char, _buffer, _buffer_length, new_length);
_buffer_length = new_length;
}
if (c == '\n') {
// null terminate it, reset the pointer and process the line
buffer[pos] = '\0';
buffer_end = pos++;
bufptr = buffer;
process_command(CHECK);
if (had_error()) {
tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
tty->print_cr("%s", buffer);
return;
}
pos = 0;
buffer_end = 0;
line_no++;
c = getc(_stream); // get next char
break;
} else if (c == '\r') {
// skip LF
} else {
buffer[pos++] = c;
_buffer[_buffer_pos++] = c;
}
c = getc(stream);
c = getc(_stream);
}
// null terminate it, reset the pointer
_buffer[_buffer_pos] = '\0'; // NL or EOF
_buffer_pos = 0;
_bufptr = _buffer;
return c;
}
// Process each line of the replay file executing each command until
// the file ends.
void process(TRAPS) {
int line_no = 1;
int c = getc(_stream);
while(c != EOF) {
c = get_line(c);
process_command(CHECK);
if (had_error()) {
tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
tty->print_cr("%s", _buffer);
return;
}
line_no++;
}
}
......@@ -396,7 +441,37 @@ class CompileReplay : public StackObj {
return true;
}
// compile <klass> <name> <signature> <entry_bci> <comp_level>
// compile <klass> <name> <signature> <entry_bci> <comp_level> inline <count> <depth> <bci> <klass> <name> <signature> ...
void* process_inline(ciMethod* imethod, Method* m, int entry_bci, int comp_level, TRAPS) {
_imethod = m;
_iklass = imethod->holder();
_entry_bci = entry_bci;
_comp_level = comp_level;
int line_no = 1;
int c = getc(_stream);
while(c != EOF) {
c = get_line(c);
// Expecting only lines with "compile" command in inline replay file.
char* cmd = parse_string();
if (cmd == NULL || strcmp("compile", cmd) != 0) {
return NULL;
}
process_compile(CHECK_NULL);
if (had_error()) {
tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
tty->print_cr("%s", _buffer);
return NULL;
}
if (_ci_inline_records != NULL && _ci_inline_records->length() > 0) {
// Found inlining record for the requested method.
return _ci_inline_records;
}
line_no++;
}
return NULL;
}
// compile <klass> <name> <signature> <entry_bci> <comp_level> inline <count> <depth> <bci> <klass> <name> <signature> ...
void process_compile(TRAPS) {
Method* method = parse_method(CHECK);
if (had_error()) return;
......@@ -410,6 +485,43 @@ class CompileReplay : public StackObj {
if (!is_valid_comp_level(comp_level)) {
return;
}
if (_imethod != NULL) {
// Replay Inlining
if (entry_bci != _entry_bci || comp_level != _comp_level) {
return;
}
const char* iklass_name = _imethod->method_holder()->name()->as_utf8();
const char* imethod_name = _imethod->name()->as_utf8();
const char* isignature = _imethod->signature()->as_utf8();
const char* klass_name = method->method_holder()->name()->as_utf8();
const char* method_name = method->name()->as_utf8();
const char* signature = method->signature()->as_utf8();
if (strcmp(iklass_name, klass_name) != 0 ||
strcmp(imethod_name, method_name) != 0 ||
strcmp(isignature, signature) != 0) {
return;
}
}
int inline_count = 0;
if (parse_tag_and_count("inline", inline_count)) {
// Record inlining data
_ci_inline_records = new GrowableArray<ciInlineRecord*>();
for (int i = 0; i < inline_count; i++) {
int depth = parse_int("inline_depth");
int bci = parse_int("inline_bci");
if (had_error()) {
break;
}
Method* inl_method = parse_method(CHECK);
if (had_error()) {
break;
}
new_ciInlineRecord(inl_method, bci, depth);
}
}
if (_imethod != NULL) {
return; // Replay Inlining
}
Klass* k = method->method_holder();
((InstanceKlass*)k)->initialize(THREAD);
if (HAS_PENDING_EXCEPTION) {
......@@ -442,11 +554,11 @@ class CompileReplay : public StackObj {
Method* method = parse_method(CHECK);
if (had_error()) return;
ciMethodRecord* rec = new_ciMethod(method);
rec->invocation_counter = parse_int("invocation_counter");
rec->backedge_counter = parse_int("backedge_counter");
rec->interpreter_invocation_count = parse_int("interpreter_invocation_count");
rec->interpreter_throwout_count = parse_int("interpreter_throwout_count");
rec->instructions_size = parse_int("instructions_size");
rec->_invocation_counter = parse_int("invocation_counter");
rec->_backedge_counter = parse_int("backedge_counter");
rec->_interpreter_invocation_count = parse_int("interpreter_invocation_count");
rec->_interpreter_throwout_count = parse_int("interpreter_throwout_count");
rec->_instructions_size = parse_int("instructions_size");
}
// ciMethodData <klass> <name> <signature> <state> <current mileage> orig <length> # # ... data <length> # # ... oops <length>
......@@ -471,32 +583,32 @@ class CompileReplay : public StackObj {
// collect and record all the needed information for later
ciMethodDataRecord* rec = new_ciMethodData(method);
rec->state = parse_int("state");
rec->current_mileage = parse_int("current_mileage");
rec->_state = parse_int("state");
rec->_current_mileage = parse_int("current_mileage");
rec->orig_data = parse_data("orig", rec->orig_data_length);
if (rec->orig_data == NULL) {
rec->_orig_data = parse_data("orig", rec->_orig_data_length);
if (rec->_orig_data == NULL) {
return;
}
rec->data = parse_intptr_data("data", rec->data_length);
if (rec->data == NULL) {
rec->_data = parse_intptr_data("data", rec->_data_length);
if (rec->_data == NULL) {
return;
}
if (!parse_tag_and_count("oops", rec->oops_length)) {
if (!parse_tag_and_count("oops", rec->_oops_length)) {
return;
}
rec->oops_handles = NEW_RESOURCE_ARRAY(jobject, rec->oops_length);
rec->oops_offsets = NEW_RESOURCE_ARRAY(int, rec->oops_length);
for (int i = 0; i < rec->oops_length; i++) {
rec->_oops_handles = NEW_RESOURCE_ARRAY(jobject, rec->_oops_length);
rec->_oops_offsets = NEW_RESOURCE_ARRAY(int, rec->_oops_length);
for (int i = 0; i < rec->_oops_length; i++) {
int offset = parse_int("offset");
if (had_error()) {
return;
}
Klass* k = parse_klass(CHECK);
rec->oops_offsets[i] = offset;
rec->_oops_offsets[i] = offset;
KlassHandle *kh = NEW_C_HEAP_OBJ(KlassHandle, mtCompiler);
::new ((void*)kh) KlassHandle(THREAD, k);
rec->oops_handles[i] = (jobject)kh;
rec->_oops_handles[i] = (jobject)kh;
}
}
......@@ -570,6 +682,9 @@ class CompileReplay : public StackObj {
case JVM_CONSTANT_Utf8:
case JVM_CONSTANT_Integer:
case JVM_CONSTANT_Float:
case JVM_CONSTANT_MethodHandle:
case JVM_CONSTANT_MethodType:
case JVM_CONSTANT_InvokeDynamic:
if (tag != cp->tag_at(i).value()) {
report_error("tag mismatch: wrong class files?");
return;
......@@ -729,10 +844,10 @@ class CompileReplay : public StackObj {
// Create and initialize a record for a ciMethod
ciMethodRecord* new_ciMethod(Method* method) {
ciMethodRecord* rec = NEW_RESOURCE_OBJ(ciMethodRecord);
rec->klass = method->method_holder()->name()->as_utf8();
rec->method = method->name()->as_utf8();
rec->signature = method->signature()->as_utf8();
ci_method_records.append(rec);
rec->_klass_name = method->method_holder()->name()->as_utf8();
rec->_method_name = method->name()->as_utf8();
rec->_signature = method->signature()->as_utf8();
_ci_method_records.append(rec);
return rec;
}
......@@ -741,11 +856,11 @@ class CompileReplay : public StackObj {
const char* klass_name = method->method_holder()->name()->as_utf8();
const char* method_name = method->name()->as_utf8();
const char* signature = method->signature()->as_utf8();
for (int i = 0; i < ci_method_records.length(); i++) {
ciMethodRecord* rec = ci_method_records.at(i);
if (strcmp(rec->klass, klass_name) == 0 &&
strcmp(rec->method, method_name) == 0 &&
strcmp(rec->signature, signature) == 0) {
for (int i = 0; i < _ci_method_records.length(); i++) {
ciMethodRecord* rec = _ci_method_records.at(i);
if (strcmp(rec->_klass_name, klass_name) == 0 &&
strcmp(rec->_method_name, method_name) == 0 &&
strcmp(rec->_signature, signature) == 0) {
return rec;
}
}
......@@ -755,10 +870,10 @@ class CompileReplay : public StackObj {
// Create and initialize a record for a ciMethodData
ciMethodDataRecord* new_ciMethodData(Method* method) {
ciMethodDataRecord* rec = NEW_RESOURCE_OBJ(ciMethodDataRecord);
rec->klass = method->method_holder()->name()->as_utf8();
rec->method = method->name()->as_utf8();
rec->signature = method->signature()->as_utf8();
ci_method_data_records.append(rec);
rec->_klass_name = method->method_holder()->name()->as_utf8();
rec->_method_name = method->name()->as_utf8();
rec->_signature = method->signature()->as_utf8();
_ci_method_data_records.append(rec);
return rec;
}
......@@ -767,25 +882,65 @@ class CompileReplay : public StackObj {
const char* klass_name = method->method_holder()->name()->as_utf8();
const char* method_name = method->name()->as_utf8();
const char* signature = method->signature()->as_utf8();
for (int i = 0; i < ci_method_data_records.length(); i++) {
ciMethodDataRecord* rec = ci_method_data_records.at(i);
if (strcmp(rec->klass, klass_name) == 0 &&
strcmp(rec->method, method_name) == 0 &&
strcmp(rec->signature, signature) == 0) {
for (int i = 0; i < _ci_method_data_records.length(); i++) {
ciMethodDataRecord* rec = _ci_method_data_records.at(i);
if (strcmp(rec->_klass_name, klass_name) == 0 &&
strcmp(rec->_method_name, method_name) == 0 &&
strcmp(rec->_signature, signature) == 0) {
return rec;
}
}
return NULL;
}
// Create and initialize a record for a ciInlineRecord
ciInlineRecord* new_ciInlineRecord(Method* method, int bci, int depth) {
ciInlineRecord* rec = NEW_RESOURCE_OBJ(ciInlineRecord);
rec->_klass_name = method->method_holder()->name()->as_utf8();
rec->_method_name = method->name()->as_utf8();
rec->_signature = method->signature()->as_utf8();
rec->_inline_bci = bci;
rec->_inline_depth = depth;
_ci_inline_records->append(rec);
return rec;
}
// Lookup inlining data for a ciMethod
ciInlineRecord* find_ciInlineRecord(Method* method, int bci, int depth) {
if (_ci_inline_records != NULL) {
return find_ciInlineRecord(_ci_inline_records, method, bci, depth);
}
return NULL;
}
static ciInlineRecord* find_ciInlineRecord(GrowableArray<ciInlineRecord*>* records,
Method* method, int bci, int depth) {
if (records != NULL) {
const char* klass_name = method->method_holder()->name()->as_utf8();
const char* method_name = method->name()->as_utf8();
const char* signature = method->signature()->as_utf8();
for (int i = 0; i < records->length(); i++) {
ciInlineRecord* rec = records->at(i);
if ((rec->_inline_bci == bci) &&
(rec->_inline_depth == depth) &&
(strcmp(rec->_klass_name, klass_name) == 0) &&
(strcmp(rec->_method_name, method_name) == 0) &&
(strcmp(rec->_signature, signature) == 0)) {
return rec;
}
}
}
return NULL;
}
const char* error_message() {
return _error_message;
}
void reset() {
_error_message = NULL;
ci_method_records.clear();
ci_method_data_records.clear();
_ci_method_records.clear();
_ci_method_data_records.clear();
}
// Take an ascii string contain \u#### escapes and convert it to utf8
......@@ -845,6 +1000,37 @@ void ciReplay::replay(TRAPS) {
vm_exit(exit_code);
}
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).");
return NULL;
}
VM_ENTRY_MARK;
// Load and parse the replay data
CompileReplay rp(InlineDataFile, THREAD);
if (!rp.can_replay()) {
tty->print_cr("ciReplay: !rp.can_replay()");
return NULL;
}
void* data = rp.process_inline(method, method->get_Method(), entry_bci, comp_level, THREAD);
if (HAS_PENDING_EXCEPTION) {
oop throwable = PENDING_EXCEPTION;
CLEAR_PENDING_EXCEPTION;
java_lang_Throwable::print(throwable, tty);
tty->cr();
java_lang_Throwable::print_stack_trace(throwable, tty);
tty->cr();
return NULL;
}
if (rp.had_error()) {
tty->print_cr("ciReplay: Failed on %s", rp.error_message());
return NULL;
}
return data;
}
int ciReplay::replay_impl(TRAPS) {
HandleMark hm;
ResourceMark rm;
......@@ -890,7 +1076,6 @@ int ciReplay::replay_impl(TRAPS) {
return exit_code;
}
void ciReplay::initialize(ciMethodData* m) {
if (replay_state == NULL) {
return;
......@@ -909,28 +1094,28 @@ void ciReplay::initialize(ciMethodData* m) {
method->print_name(tty);
tty->cr();
} else {
m->_state = rec->state;
m->_current_mileage = rec->current_mileage;
if (rec->data_length != 0) {
assert(m->_data_size == rec->data_length * (int)sizeof(rec->data[0]), "must agree");
m->_state = rec->_state;
m->_current_mileage = rec->_current_mileage;
if (rec->_data_length != 0) {
assert(m->_data_size == rec->_data_length * (int)sizeof(rec->_data[0]), "must agree");
// Write the correct ciObjects back into the profile data
ciEnv* env = ciEnv::current();
for (int i = 0; i < rec->oops_length; i++) {
KlassHandle *h = (KlassHandle *)rec->oops_handles[i];
*(ciMetadata**)(rec->data + rec->oops_offsets[i]) =
for (int i = 0; i < rec->_oops_length; i++) {
KlassHandle *h = (KlassHandle *)rec->_oops_handles[i];
*(ciMetadata**)(rec->_data + rec->_oops_offsets[i]) =
env->get_metadata((*h)());
}
// Copy the updated profile data into place as intptr_ts
#ifdef _LP64
Copy::conjoint_jlongs_atomic((jlong *)rec->data, (jlong *)m->_data, rec->data_length);
Copy::conjoint_jlongs_atomic((jlong *)rec->_data, (jlong *)m->_data, rec->_data_length);
#else
Copy::conjoint_jints_atomic((jint *)rec->data, (jint *)m->_data, rec->data_length);
Copy::conjoint_jints_atomic((jint *)rec->_data, (jint *)m->_data, rec->_data_length);
#endif
}
// copy in the original header
Copy::conjoint_jbytes(rec->orig_data, (char*)&m->_orig, rec->orig_data_length);
Copy::conjoint_jbytes(rec->_orig_data, (char*)&m->_orig, rec->_orig_data_length);
}
}
......@@ -939,12 +1124,38 @@ bool ciReplay::should_not_inline(ciMethod* method) {
if (replay_state == NULL) {
return false;
}
VM_ENTRY_MARK;
// ciMethod without a record shouldn't be inlined.
return replay_state->find_ciMethodRecord(method->get_Method()) == NULL;
}
bool ciReplay::should_inline(void* data, ciMethod* method, int bci, int inline_depth) {
if (data != NULL) {
GrowableArray<ciInlineRecord*>* records = (GrowableArray<ciInlineRecord*>*)data;
VM_ENTRY_MARK;
// Inline record are ordered by bci and depth.
return CompileReplay::find_ciInlineRecord(records, method->get_Method(), bci, inline_depth) != NULL;
} else if (replay_state != NULL) {
VM_ENTRY_MARK;
// Inline record are ordered by bci and depth.
return replay_state->find_ciInlineRecord(method->get_Method(), bci, inline_depth) != NULL;
}
return false;
}
bool ciReplay::should_not_inline(void* data, ciMethod* method, int bci, int inline_depth) {
if (data != NULL) {
GrowableArray<ciInlineRecord*>* records = (GrowableArray<ciInlineRecord*>*)data;
VM_ENTRY_MARK;
// Inline record are ordered by bci and depth.
return CompileReplay::find_ciInlineRecord(records, method->get_Method(), bci, inline_depth) == NULL;
} else if (replay_state != NULL) {
VM_ENTRY_MARK;
// Inline record are ordered by bci and depth.
return replay_state->find_ciInlineRecord(method->get_Method(), bci, inline_depth) == NULL;
}
return false;
}
void ciReplay::initialize(ciMethod* m) {
if (replay_state == NULL) {
......@@ -965,14 +1176,14 @@ void ciReplay::initialize(ciMethod* m) {
tty->cr();
} else {
EXCEPTION_CONTEXT;
// m->_instructions_size = rec->instructions_size;
// m->_instructions_size = rec->_instructions_size;
m->_instructions_size = -1;
m->_interpreter_invocation_count = rec->interpreter_invocation_count;
m->_interpreter_throwout_count = rec->interpreter_throwout_count;
m->_interpreter_invocation_count = rec->_interpreter_invocation_count;
m->_interpreter_throwout_count = rec->_interpreter_throwout_count;
MethodCounters* mcs = method->get_method_counters(CHECK_AND_CLEAR);
guarantee(mcs != NULL, "method counters allocation failed");
mcs->invocation_counter()->_counter = rec->invocation_counter;
mcs->backedge_counter()->_counter = rec->backedge_counter;
mcs->invocation_counter()->_counter = rec->_invocation_counter;
mcs->backedge_counter()->_counter = rec->_backedge_counter;
}
}
......
......@@ -29,6 +29,73 @@
// ciReplay
//
// Replay compilation of a java method by using an information in replay file.
// Replay inlining decisions during compilation by using an information in inline file.
//
// NOTE: these replay functions only exist in debug version of VM.
//
// Replay compilation.
// -------------------
//
// Replay data file replay.txt can be created by Serviceability Agent
// from a core file, see agent/doc/cireplay.html
//
// $ java -cp <jdk>/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB
// hsdb> attach <jdk>/bin/java ./core
// hsdb> threads
// t@10 Service Thread
// t@9 C2 CompilerThread0
// t@8 Signal Dispatcher
// t@7 Finalizer
// t@6 Reference Handler
// t@2 main
// hsdb> dumpreplaydata t@9 > replay.txt
// hsdb> quit
//
// (Note: SA could be also used to extract app.jar and boot.jar files
// from core file to replay compilation if only core file is available)
//
// Replay data file replay_pid%p.log is also created when VM crashes
// in Compiler thread during compilation. It is controlled by
// DumpReplayDataOnError flag which is ON by default.
//
// Replay file replay_pid%p_compid%d.log can be created
// for the specified java method during normal execution using
// CompileCommand option DumpReplay:
//
// -XX:CompileCommand=option,Benchmark::test,DumpReplay
//
// In this case the file name has additional compilation id "_compid%d"
// because the method could be compiled several times.
//
// To replay compilation the replay file should be specified:
//
// -XX:+ReplayCompiles -XX:ReplayDataFile=replay_pid2133.log
//
// VM thread reads data from the file immediately after VM initialization
// and puts the compilation task on compile queue. After that it goes into
// wait state (BackgroundCompilation flag is set to false) since there is no
// a program to execute. VM exits when the compilation is finished.
//
//
// Replay inlining.
// ----------------
//
// Replay inlining file inline_pid%p_compid%d.log is created for
// a specific java method during normal execution of a java program
// using CompileCommand option DumpInline:
//
// -XX:CompileCommand=option,Benchmark::test,DumpInline
//
// To replay inlining the replay file and the method should be specified:
//
// -XX:CompileCommand=option,Benchmark::test,ReplayInline -XX:InlineDataFile=inline_pid3244_compid6.log
//
// The difference from replay compilation is that replay inlining
// is performed during normal java program execution.
//
class ciReplay {
CI_PACKAGE_ACCESS
......@@ -37,7 +104,11 @@ class ciReplay {
static int replay_impl(TRAPS);
public:
// Replay specified compilation and exit VM.
static void replay(TRAPS);
// 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);
// These are used by the CI to fill in the cached data from the
// replay file when replaying compiles.
......@@ -48,6 +119,8 @@ class ciReplay {
static bool is_loaded(Klass* klass);
static bool should_not_inline(ciMethod* method);
static bool should_inline(void* data, ciMethod* method, int bci, int inline_depth);
static bool should_not_inline(void* data, ciMethod* method, int bci, int inline_depth);
#endif
};
......
......@@ -140,7 +140,7 @@ void ResourceObj::operator delete [](void* p) {
void ResourceObj::set_allocation_type(address res, allocation_type type) {
// Set allocation type in the resource object
uintptr_t allocation = (uintptr_t)res;
assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least");
assert((allocation & allocation_mask) == 0, err_msg("address should be aligned to 4 bytes at least: " PTR_FORMAT, res));
assert(type <= allocation_mask, "incorrect allocation type");
ResourceObj* resobj = (ResourceObj *)res;
resobj->_allocation_t[0] = ~(allocation + type);
......
......@@ -50,7 +50,10 @@ InlineTree::InlineTree(Compile* c,
_subtrees(c->comp_arena(), 2, 0, NULL),
_msg(NULL)
{
NOT_PRODUCT(_count_inlines = 0;)
#ifndef PRODUCT
_count_inlines = 0;
_forced_inline = false;
#endif
if (_caller_jvms != NULL) {
// Keep a private copy of the caller_jvms:
_caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms());
......@@ -81,7 +84,10 @@ InlineTree::InlineTree(Compile* c, ciMethod* callee_method, JVMState* caller_jvm
_count_inline_bcs(method()->code_size()),
_msg(NULL)
{
NOT_PRODUCT(_count_inlines = 0;)
#ifndef PRODUCT
_count_inlines = 0;
_forced_inline = false;
#endif
assert(!UseOldInlining, "do not use for old stuff");
}
......@@ -128,9 +134,19 @@ bool InlineTree::should_inline(ciMethod* callee_method, ciMethod* caller_method,
tty->print_cr("Inlined method is hot: ");
}
set_msg("force inline by CompilerOracle");
_forced_inline = true;
return true;
}
#ifndef PRODUCT
int inline_depth = inline_level()+1;
if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
set_msg("force inline by ciReplay");
_forced_inline = true;
return true;
}
#endif
int size = callee_method->code_size_for_inlining();
// Check for too many throws (and not too huge)
......@@ -264,6 +280,18 @@ bool InlineTree::should_not_inline(ciMethod *callee_method,
}
#ifndef PRODUCT
int caller_bci = jvms->bci();
int inline_depth = inline_level()+1;
if (ciReplay::should_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
set_msg("force inline by ciReplay");
return false;
}
if (ciReplay::should_not_inline(C->replay_inline_data(), callee_method, caller_bci, inline_depth)) {
set_msg("disallowed by ciReplay");
return true;
}
if (ciReplay::should_not_inline(callee_method)) {
set_msg("disallowed by ciReplay");
return true;
......@@ -343,6 +371,7 @@ bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
}
}
_forced_inline = false; // Reset
if (!should_inline(callee_method, caller_method, caller_bci, profile,
wci_result)) {
return false;
......@@ -373,10 +402,10 @@ bool InlineTree::try_to_inline(ciMethod* callee_method, ciMethod* caller_method,
if ((!UseInterpreter || CompileTheWorld) &&
is_init_with_ea(callee_method, caller_method, C)) {
// Escape Analysis stress testing when running Xcomp or CTW:
// inline constructors even if they are not reached.
} else if (forced_inline()) {
// Inlining was forced by CompilerOracle or ciReplay
} else if (profile.count() == 0) {
// don't inline unreached call sites
set_msg("call site not reached");
......@@ -700,12 +729,28 @@ InlineTree* InlineTree::find_subtree_from_root(InlineTree* root, JVMState* jvms,
return iltp;
}
// Count number of nodes in this subtree
int InlineTree::count() const {
int result = 1;
for (int i = 0 ; i < _subtrees.length(); i++) {
result += _subtrees.at(i)->count();
}
return result;
}
void InlineTree::dump_replay_data(outputStream* out) {
out->print(" %d %d ", inline_level(), caller_bci());
method()->dump_name_as_ascii(out);
for (int i = 0 ; i < _subtrees.length(); i++) {
_subtrees.at(i)->dump_replay_data(out);
}
}
#ifndef PRODUCT
void InlineTree::print_impl(outputStream* st, int indent) const {
for (int i = 0; i < indent; i++) st->print(" ");
st->print(" @ %d ", caller_bci());
st->print(" @ %d", caller_bci());
method()->print_short_name(st);
st->cr();
......
......@@ -25,6 +25,7 @@
#include "precompiled.hpp"
#include "asm/macroAssembler.hpp"
#include "asm/macroAssembler.inline.hpp"
#include "ci/ciReplay.hpp"
#include "classfile/systemDictionary.hpp"
#include "code/exceptionHandlerTable.hpp"
#include "code/nmethod.hpp"
......@@ -647,6 +648,7 @@ Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr
_printer(IdealGraphPrinter::printer()),
#endif
_congraph(NULL),
_replay_inline_data(NULL),
_late_inlines(comp_arena(), 2, 0, NULL),
_string_late_inlines(comp_arena(), 2, 0, NULL),
_boxing_late_inlines(comp_arena(), 2, 0, NULL),
......@@ -680,6 +682,10 @@ Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr
}
set_print_assembly(print_opto_assembly);
set_parsed_irreducible_loop(false);
if (method()->has_option("ReplayInline")) {
_replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
}
#endif
set_print_inlining(PrintInlining || method()->has_option("PrintInlining") NOT_PRODUCT( || PrintOptoInlining));
set_print_intrinsics(PrintIntrinsics || method()->has_option("PrintIntrinsics"));
......@@ -849,6 +855,15 @@ Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr
#endif
NOT_PRODUCT( verify_barriers(); )
// Dump compilation data to replay it.
if (method()->has_option("DumpReplay")) {
env()->dump_replay_data(_compile_id);
}
if (method()->has_option("DumpInline") && (ilt() != NULL)) {
env()->dump_inline_data(_compile_id);
}
// Now that we know the size of all the monitors we can add a fixed slot
// for the original deopt pc.
......@@ -938,6 +953,7 @@ Compile::Compile( ciEnv* ci_env,
_dead_node_list(comp_arena()),
_dead_node_count(0),
_congraph(NULL),
_replay_inline_data(NULL),
_number_of_mh_late_inlines(0),
_inlining_progress(false),
_inlining_incrementally(false),
......@@ -3757,6 +3773,16 @@ void Compile::dump_inlining() {
}
}
// Dump inlining replay data to the stream.
// Don't change thread state and acquire any locks.
void Compile::dump_inline_data(outputStream* out) {
InlineTree* inl_tree = ilt();
if (inl_tree != NULL) {
out->print(" inline %d", inl_tree->count());
inl_tree->dump_replay_data(out);
}
}
int Compile::cmp_expensive_nodes(Node* n1, Node* n2) {
if (n1->Opcode() < n2->Opcode()) return -1;
else if (n1->Opcode() > n2->Opcode()) return 1;
......
......@@ -431,6 +431,8 @@ class Compile : public Phase {
// Are we within a PreserveJVMState block?
int _preserve_jvm_state;
void* _replay_inline_data; // Pointer to data loaded from file
public:
outputStream* print_inlining_stream() const {
......@@ -465,6 +467,11 @@ class Compile : public Phase {
print_inlining_stream()->print(ss.as_string());
}
void* replay_inline_data() const { return _replay_inline_data; }
// Dump inlining replay data to the stream.
void dump_inline_data(outputStream* out);
private:
// Matching, CFG layout, allocation, code generation
PhaseCFG* _cfg; // Results of CFG finding
......
......@@ -141,6 +141,13 @@ public:
GrowableArray<InlineTree*> subtrees() { return _subtrees; }
void print_value_on(outputStream* st) const PRODUCT_RETURN;
bool _forced_inline; // Inlining was forced by CompilerOracle or ciReplay
bool forced_inline() const { return _forced_inline; }
// Count number of nodes in this subtree
int count() const;
// Dump inlining replay data to the stream.
void dump_replay_data(outputStream* out);
};
......
......@@ -3342,6 +3342,10 @@ class CommandLineFlags {
"File containing compilation replay information" \
"[default: ./replay_pid%p.log] (%p replaced with pid)") \
\
product(ccstr, InlineDataFile, NULL, \
"File containing inlining replay information" \
"[default: ./inline_pid%p.log] (%p replaced with pid)") \
\
develop(intx, ReplaySuppressInitializers, 2, \
"Control handling of class initialization during replay: " \
"0 - don't do anything special; " \
......
......@@ -1040,7 +1040,7 @@ void VMError::report_and_die() {
OnError = NULL;
}
static bool skip_replay = false;
static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay
if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) {
skip_replay = true;
ciEnv* env = ciEnv::current();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册