提交 4a3dd894 编写于 作者: K kvn

6834177: Running jsynprog on Solaris Nevada can cause JVM crash

Summary: Use CodeCache buffer blob instead of static buffer in AdapterHandlerLibrary.
Reviewed-by: never
上级 470c1589
...@@ -60,6 +60,11 @@ jlong DTraceJSDT::activate( ...@@ -60,6 +60,11 @@ jlong DTraceJSDT::activate(
methodHandle h_method = methodHandle h_method =
methodHandle(THREAD, JNIHandles::resolve_jmethod_id(probe->method)); methodHandle(THREAD, JNIHandles::resolve_jmethod_id(probe->method));
nmethod* nm = AdapterHandlerLibrary::create_dtrace_nmethod(h_method); nmethod* nm = AdapterHandlerLibrary::create_dtrace_nmethod(h_method);
if (nm == NULL) {
delete probes;
THROW_MSG_0(vmSymbols::java_lang_RuntimeException(),
"Unable to register DTrace probes (CodeCache: no room for DTrace nmethods).");
}
h_method()->set_not_compilable(CompLevel_highest_tier); h_method()->set_not_compilable(CompLevel_highest_tier);
h_method()->set_code(h_method, nm); h_method()->set_code(h_method, nm);
probes->nmethod_at_put(count++, nm); probes->nmethod_at_put(count++, nm);
......
...@@ -1776,7 +1776,14 @@ const char* AdapterHandlerEntry::name = "I2C/C2I adapters"; ...@@ -1776,7 +1776,14 @@ const char* AdapterHandlerEntry::name = "I2C/C2I adapters";
GrowableArray<uint64_t>* AdapterHandlerLibrary::_fingerprints = NULL; GrowableArray<uint64_t>* AdapterHandlerLibrary::_fingerprints = NULL;
GrowableArray<AdapterHandlerEntry* >* AdapterHandlerLibrary::_handlers = NULL; GrowableArray<AdapterHandlerEntry* >* AdapterHandlerLibrary::_handlers = NULL;
const int AdapterHandlerLibrary_size = 16*K; const int AdapterHandlerLibrary_size = 16*K;
u_char AdapterHandlerLibrary::_buffer[AdapterHandlerLibrary_size + 32]; BufferBlob* AdapterHandlerLibrary::_buffer = NULL;
BufferBlob* AdapterHandlerLibrary::buffer_blob() {
// Should be called only when AdapterHandlerLibrary_lock is active.
if (_buffer == NULL) // Initialize lazily
_buffer = BufferBlob::create("adapters", AdapterHandlerLibrary_size);
return _buffer;
}
void AdapterHandlerLibrary::initialize() { void AdapterHandlerLibrary::initialize() {
if (_fingerprints != NULL) return; if (_fingerprints != NULL) return;
...@@ -1812,7 +1819,9 @@ int AdapterHandlerLibrary::get_create_adapter_index(methodHandle method) { ...@@ -1812,7 +1819,9 @@ int AdapterHandlerLibrary::get_create_adapter_index(methodHandle method) {
assert(ic_miss != NULL, "must have handler"); assert(ic_miss != NULL, "must have handler");
int result; int result;
NOT_PRODUCT(int code_size);
BufferBlob *B = NULL; BufferBlob *B = NULL;
AdapterHandlerEntry* entry = NULL;
uint64_t fingerprint; uint64_t fingerprint;
{ {
MutexLocker mu(AdapterHandlerLibrary_lock); MutexLocker mu(AdapterHandlerLibrary_lock);
...@@ -1850,42 +1859,45 @@ int AdapterHandlerLibrary::get_create_adapter_index(methodHandle method) { ...@@ -1850,42 +1859,45 @@ int AdapterHandlerLibrary::get_create_adapter_index(methodHandle method) {
// Create I2C & C2I handlers // Create I2C & C2I handlers
ResourceMark rm; ResourceMark rm;
// Improve alignment slightly
u_char *buf = (u_char*)(((intptr_t)_buffer + CodeEntryAlignment-1) & ~(CodeEntryAlignment-1));
CodeBuffer buffer(buf, AdapterHandlerLibrary_size);
short buffer_locs[20];
buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs,
sizeof(buffer_locs)/sizeof(relocInfo));
MacroAssembler _masm(&buffer);
// Fill in the signature array, for the calling-convention call.
int total_args_passed = method->size_of_parameters(); // All args on stack
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType,total_args_passed);
VMRegPair * regs = NEW_RESOURCE_ARRAY(VMRegPair ,total_args_passed);
int i=0;
if( !method->is_static() ) // Pass in receiver first
sig_bt[i++] = T_OBJECT;
for( SignatureStream ss(method->signature()); !ss.at_return_type(); ss.next()) {
sig_bt[i++] = ss.type(); // Collect remaining bits of signature
if( ss.type() == T_LONG || ss.type() == T_DOUBLE )
sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
}
assert( i==total_args_passed, "" );
// Now get the re-packed compiled-Java layout. BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
int comp_args_on_stack; if (buf != NULL) {
CodeBuffer buffer(buf->instructions_begin(), buf->instructions_size());
short buffer_locs[20];
buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs,
sizeof(buffer_locs)/sizeof(relocInfo));
MacroAssembler _masm(&buffer);
// Fill in the signature array, for the calling-convention call.
int total_args_passed = method->size_of_parameters(); // All args on stack
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType,total_args_passed);
VMRegPair * regs = NEW_RESOURCE_ARRAY(VMRegPair ,total_args_passed);
int i=0;
if( !method->is_static() ) // Pass in receiver first
sig_bt[i++] = T_OBJECT;
for( SignatureStream ss(method->signature()); !ss.at_return_type(); ss.next()) {
sig_bt[i++] = ss.type(); // Collect remaining bits of signature
if( ss.type() == T_LONG || ss.type() == T_DOUBLE )
sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
}
assert( i==total_args_passed, "" );
// Get a description of the compiled java calling convention and the largest used (VMReg) stack slot usage // Now get the re-packed compiled-Java layout.
comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false); int comp_args_on_stack;
AdapterHandlerEntry* entry = SharedRuntime::generate_i2c2i_adapters(&_masm, // Get a description of the compiled java calling convention and the largest used (VMReg) stack slot usage
total_args_passed, comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
comp_args_on_stack,
sig_bt,
regs);
B = BufferBlob::create(AdapterHandlerEntry::name, &buffer); entry = SharedRuntime::generate_i2c2i_adapters(&_masm,
total_args_passed,
comp_args_on_stack,
sig_bt,
regs);
B = BufferBlob::create(AdapterHandlerEntry::name, &buffer);
NOT_PRODUCT(code_size = buffer.code_size());
}
if (B == NULL) { if (B == NULL) {
// CodeCache is full, disable compilation // CodeCache is full, disable compilation
// Ought to log this but compile log is only per compile thread // Ought to log this but compile log is only per compile thread
...@@ -1912,9 +1924,9 @@ int AdapterHandlerLibrary::get_create_adapter_index(methodHandle method) { ...@@ -1912,9 +1924,9 @@ int AdapterHandlerLibrary::get_create_adapter_index(methodHandle method) {
tty->cr(); tty->cr();
tty->print_cr("i2c argument handler #%d for: %s %s (fingerprint = 0x%llx, %d bytes generated)", tty->print_cr("i2c argument handler #%d for: %s %s (fingerprint = 0x%llx, %d bytes generated)",
_handlers->length(), (method->is_static() ? "static" : "receiver"), _handlers->length(), (method->is_static() ? "static" : "receiver"),
method->signature()->as_C_string(), fingerprint, buffer.code_size() ); method->signature()->as_C_string(), fingerprint, code_size );
tty->print_cr("c2i argument handler starts at %p",entry->get_c2i_entry()); tty->print_cr("c2i argument handler starts at %p",entry->get_c2i_entry());
Disassembler::decode(entry->get_i2c_entry(), entry->get_i2c_entry() + buffer.code_size()); Disassembler::decode(entry->get_i2c_entry(), entry->get_i2c_entry() + code_size);
} }
#endif #endif
...@@ -1982,42 +1994,44 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method) { ...@@ -1982,42 +1994,44 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method) {
return nm; return nm;
} }
// Improve alignment slightly ResourceMark rm;
u_char* buf = (u_char*)(((intptr_t)_buffer + CodeEntryAlignment-1) & ~(CodeEntryAlignment-1));
CodeBuffer buffer(buf, AdapterHandlerLibrary_size);
// Need a few relocation entries
double locs_buf[20];
buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
MacroAssembler _masm(&buffer);
// Fill in the signature array, for the calling-convention call.
int total_args_passed = method->size_of_parameters();
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType,total_args_passed);
VMRegPair * regs = NEW_RESOURCE_ARRAY(VMRegPair ,total_args_passed);
int i=0;
if( !method->is_static() ) // Pass in receiver first
sig_bt[i++] = T_OBJECT;
SignatureStream ss(method->signature());
for( ; !ss.at_return_type(); ss.next()) {
sig_bt[i++] = ss.type(); // Collect remaining bits of signature
if( ss.type() == T_LONG || ss.type() == T_DOUBLE )
sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
}
assert( i==total_args_passed, "" );
BasicType ret_type = ss.type();
// Now get the compiled-Java layout as input arguments
int comp_args_on_stack;
comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
// Generate the compiled-to-native wrapper code BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
nm = SharedRuntime::generate_native_wrapper(&_masm, if (buf != NULL) {
method, CodeBuffer buffer(buf->instructions_begin(), buf->instructions_size());
total_args_passed, double locs_buf[20];
comp_args_on_stack, buffer.insts()->initialize_shared_locs((relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
sig_bt,regs, MacroAssembler _masm(&buffer);
ret_type);
// Fill in the signature array, for the calling-convention call.
int total_args_passed = method->size_of_parameters();
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType,total_args_passed);
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair,total_args_passed);
int i=0;
if( !method->is_static() ) // Pass in receiver first
sig_bt[i++] = T_OBJECT;
SignatureStream ss(method->signature());
for( ; !ss.at_return_type(); ss.next()) {
sig_bt[i++] = ss.type(); // Collect remaining bits of signature
if( ss.type() == T_LONG || ss.type() == T_DOUBLE )
sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
}
assert( i==total_args_passed, "" );
BasicType ret_type = ss.type();
// Now get the compiled-Java layout as input arguments
int comp_args_on_stack;
comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
// Generate the compiled-to-native wrapper code
nm = SharedRuntime::generate_native_wrapper(&_masm,
method,
total_args_passed,
comp_args_on_stack,
sig_bt,regs,
ret_type);
}
} }
// Must unlock before calling set_code // Must unlock before calling set_code
...@@ -2077,18 +2091,20 @@ nmethod *AdapterHandlerLibrary::create_dtrace_nmethod(methodHandle method) { ...@@ -2077,18 +2091,20 @@ nmethod *AdapterHandlerLibrary::create_dtrace_nmethod(methodHandle method) {
return nm; return nm;
} }
// Improve alignment slightly ResourceMark rm;
u_char* buf = (u_char*)
(((intptr_t)_buffer + CodeEntryAlignment-1) & ~(CodeEntryAlignment-1)); BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
CodeBuffer buffer(buf, AdapterHandlerLibrary_size); if (buf != NULL) {
// Need a few relocation entries CodeBuffer buffer(buf->instructions_begin(), buf->instructions_size());
double locs_buf[20]; // Need a few relocation entries
buffer.insts()->initialize_shared_locs( double locs_buf[20];
buffer.insts()->initialize_shared_locs(
(relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo)); (relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
MacroAssembler _masm(&buffer); MacroAssembler _masm(&buffer);
// Generate the compiled-to-native wrapper code // Generate the compiled-to-native wrapper code
nm = SharedRuntime::generate_dtrace_nmethod(&_masm, method); nm = SharedRuntime::generate_dtrace_nmethod(&_masm, method);
}
} }
return nm; return nm;
} }
......
...@@ -557,12 +557,13 @@ class AdapterHandlerEntry : public CHeapObj { ...@@ -557,12 +557,13 @@ class AdapterHandlerEntry : public CHeapObj {
class AdapterHandlerLibrary: public AllStatic { class AdapterHandlerLibrary: public AllStatic {
private: private:
static u_char _buffer[]; // the temporary code buffer static BufferBlob* _buffer; // the temporary code buffer in CodeCache
static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection
static GrowableArray<AdapterHandlerEntry*> * _handlers; // the corresponding handlers static GrowableArray<AdapterHandlerEntry*> * _handlers; // the corresponding handlers
enum { enum {
AbstractMethodHandler = 1 // special handler for abstract methods AbstractMethodHandler = 1 // special handler for abstract methods
}; };
static BufferBlob* buffer_blob();
static void initialize(); static void initialize();
static int get_create_adapter_index(methodHandle method); static int get_create_adapter_index(methodHandle method);
static address get_i2c_entry( int index ) { static address get_i2c_entry( int index ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册