# HG changeset patch # User Thomas Wuerthinger # Date 1372252931 -7200 # Node ID 0ba44a5a842094aafd4d048c11c3c8a901e41f84 # Parent 5d460d3465fda3a8eaa182ecad59bf6b8fa5191e Add sanity check to avoid overwriting the reserved code buffer for very large methods. diff -r 5d460d3465fd -r 0ba44a5a8420 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed Jun 26 15:17:17 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Wed Jun 26 15:22:11 2013 +0200 @@ -144,7 +144,7 @@ // Must be kept in sync with enum in graalEnv.hpp public enum CodeInstallResult { - OK, DEPENDENCIES_FAILED, CACHE_FULL + OK, DEPENDENCIES_FAILED, CACHE_FULL, CODE_TOO_LARGE } /** diff -r 5d460d3465fd -r 0ba44a5a8420 src/share/vm/graal/graalCodeInstaller.cpp --- a/src/share/vm/graal/graalCodeInstaller.cpp Wed Jun 26 15:17:17 2013 +0200 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Wed Jun 26 15:22:11 2013 +0200 @@ -369,7 +369,10 @@ { No_Safepoint_Verifier no_safepoint; initialize_fields(JNIHandles::resolve(compiled_code_obj)); - initialize_buffer(buffer); + if (!initialize_buffer(buffer)) { + result = GraalEnv::code_too_large; + return; + } process_exception_handlers(); } @@ -427,7 +430,7 @@ } // perform data and call relocation on the CodeBuffer -void CodeInstaller::initialize_buffer(CodeBuffer& buffer) { +bool CodeInstaller::initialize_buffer(CodeBuffer& buffer) { int locs_buffer_size = _sites->length() * (relocInfo::length_limit + sizeof(relocInfo)); char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); buffer.insts()->initialize_shared_locs((relocInfo*)locs_buffer, locs_buffer_size / sizeof(relocInfo)); @@ -443,8 +446,12 @@ _constants = buffer.consts(); // copy the code into the newly created CodeBuffer + address end_pc = _instructions->start() + _code_size; + if (!_instructions->allocates2(end_pc)) { + return false; + } memcpy(_instructions->start(), _code->base(T_BYTE), _code_size); - _instructions->set_end(_instructions->start() + _code_size); + _instructions->set_end(end_pc); for (int i = 0; i < _sites->length(); i++) { oop site=((objArrayOop) (_sites))->obj_at(i); @@ -486,6 +493,7 @@ } } #endif + return true; } void CodeInstaller::assumption_MethodContents(Handle assumption) { diff -r 5d460d3465fd -r 0ba44a5a8420 src/share/vm/graal/graalCodeInstaller.hpp --- a/src/share/vm/graal/graalCodeInstaller.hpp Wed Jun 26 15:17:17 2013 +0200 +++ b/src/share/vm/graal/graalCodeInstaller.hpp Wed Jun 26 15:22:11 2013 +0200 @@ -94,7 +94,7 @@ void initialize_assumptions(oop target_method); // perform data and call relocation on the CodeBuffer - void initialize_buffer(CodeBuffer& buffer); + bool initialize_buffer(CodeBuffer& buffer); void assumption_MethodContents(Handle assumption); void assumption_NoFinalizableSubclass(Handle assumption); diff -r 5d460d3465fd -r 0ba44a5a8420 src/share/vm/graal/graalEnv.hpp --- a/src/share/vm/graal/graalEnv.hpp Wed Jun 26 15:17:17 2013 +0200 +++ b/src/share/vm/graal/graalEnv.hpp Wed Jun 26 15:22:11 2013 +0200 @@ -62,7 +62,8 @@ enum CodeInstallResult { ok, dependencies_failed, - cache_full + cache_full, + code_too_large }; // Look up a klass by name from a particular class loader (the accessor's).