8172791: Issues with JEP 270 (ReservedStackArea)

Reviewed-by: dcubed, thartmann
This commit is contained in:
Andrew Haley 2017-08-11 16:29:00 -04:00 committed by Frederic Parain
parent ebcca449a0
commit 37bbfcb2fa
6 changed files with 31 additions and 11 deletions

View file

@ -1089,7 +1089,6 @@ void InterpreterMacroAssembler::remove_activation(
call_VM_leaf( call_VM_leaf(
CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread); CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), rthread);
push(rthread);
call_VM(noreg, CAST_FROM_FN_PTR(address, call_VM(noreg, CAST_FROM_FN_PTR(address,
InterpreterRuntime::throw_delayed_StackOverflowError)); InterpreterRuntime::throw_delayed_StackOverflowError));
should_not_reach_here(); should_not_reach_here();

View file

@ -209,6 +209,14 @@ ScopeDesc* CompiledMethod::scope_desc_at(address pc) {
pd->return_oop()); pd->return_oop());
} }
ScopeDesc* CompiledMethod::scope_desc_near(address pc) {
PcDesc* pd = pc_desc_near(pc);
guarantee(pd != NULL, "scope must be present");
return new ScopeDesc(this, pd->scope_decode_offset(),
pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(),
pd->return_oop());
}
void CompiledMethod::cleanup_inline_caches(bool clean_all/*=false*/) { void CompiledMethod::cleanup_inline_caches(bool clean_all/*=false*/) {
assert_locked_or_safepoint(CompiledIC_lock); assert_locked_or_safepoint(CompiledIC_lock);

View file

@ -213,11 +213,12 @@ public:
// ScopeDesc retrieval operation // ScopeDesc retrieval operation
PcDesc* pc_desc_at(address pc) { return find_pc_desc(pc, false); } PcDesc* pc_desc_at(address pc) { return find_pc_desc(pc, false); }
// pc_desc_near returns the first PcDesc at or after the givne pc. // pc_desc_near returns the first PcDesc at or after the given pc.
PcDesc* pc_desc_near(address pc) { return find_pc_desc(pc, true); } PcDesc* pc_desc_near(address pc) { return find_pc_desc(pc, true); }
// ScopeDesc for an instruction // ScopeDesc for an instruction
ScopeDesc* scope_desc_at(address pc); ScopeDesc* scope_desc_at(address pc);
ScopeDesc* scope_desc_near(address pc);
bool is_at_poll_return(address pc); bool is_at_poll_return(address pc);
bool is_at_poll_or_poll_return(address pc); bool is_at_poll_or_poll_return(address pc);

View file

@ -993,7 +993,8 @@ Compile::Compile( ciEnv* ci_env,
_print_inlining_output(NULL), _print_inlining_output(NULL),
_allowed_reasons(0), _allowed_reasons(0),
_interpreter_frame_size(0), _interpreter_frame_size(0),
_max_node_limit(MaxNodeLimit) { _max_node_limit(MaxNodeLimit),
_has_reserved_stack_access(false) {
C = this; C = this;
TraceTime t1(NULL, &_t_totalCompilation, CITime, false); TraceTime t1(NULL, &_t_totalCompilation, CITime, false);

View file

@ -3128,11 +3128,14 @@ void AdapterHandlerLibrary::print_statistics() {
JRT_LEAF(void, SharedRuntime::enable_stack_reserved_zone(JavaThread* thread)) JRT_LEAF(void, SharedRuntime::enable_stack_reserved_zone(JavaThread* thread))
assert(thread->is_Java_thread(), "Only Java threads have a stack reserved zone"); assert(thread->is_Java_thread(), "Only Java threads have a stack reserved zone");
if (thread->stack_reserved_zone_disabled()) {
thread->enable_stack_reserved_zone(); thread->enable_stack_reserved_zone();
}
thread->set_reserved_stack_activation(thread->stack_base()); thread->set_reserved_stack_activation(thread->stack_base());
JRT_END JRT_END
frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* thread, frame fr) { frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* thread, frame fr) {
ResourceMark rm(thread);
frame activation; frame activation;
CompiledMethod* nm = NULL; CompiledMethod* nm = NULL;
int count = 1; int count = 1;
@ -3141,17 +3144,28 @@ frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* thread
while (true) { while (true) {
Method* method = NULL; Method* method = NULL;
bool found = false;
if (fr.is_interpreted_frame()) { if (fr.is_interpreted_frame()) {
method = fr.interpreter_frame_method(); method = fr.interpreter_frame_method();
if (method != NULL && method->has_reserved_stack_access()) {
found = true;
}
} else { } else {
CodeBlob* cb = fr.cb(); CodeBlob* cb = fr.cb();
if (cb != NULL && cb->is_compiled()) { if (cb != NULL && cb->is_compiled()) {
nm = cb->as_compiled_method(); nm = cb->as_compiled_method();
method = nm->method(); method = nm->method();
// scope_desc_near() must be used, instead of scope_desc_at() because on
// SPARC, the pcDesc can be on the delay slot after the call instruction.
for (ScopeDesc *sd = nm->scope_desc_near(fr.pc()); sd != NULL; sd = sd->sender()) {
method = sd->method();
if (method != NULL && method->has_reserved_stack_access()) {
found = true;
} }
} }
if ((method != NULL) && method->has_reserved_stack_access()) { }
ResourceMark rm(thread); }
if (found) {
activation = fr; activation = fr;
warning("Potentially dangerous stack overflow in " warning("Potentially dangerous stack overflow in "
"ReservedStackAccess annotated method %s [%d]", "ReservedStackAccess annotated method %s [%d]",

View file

@ -26,8 +26,7 @@
* @library /test/lib * @library /test/lib
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.vm.annotation * @modules java.base/jdk.internal.vm.annotation
* @run main/othervm -Xint ReservedStackTest * @run main/othervm -XX:MaxInlineLevel=2 -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
* @run main/othervm -XX:-Inline -XX:CompileCommand=exclude,java/util/concurrent/locks/AbstractOwnableSynchronizer.setExclusiveOwnerThread ReservedStackTest
*/ */
/* The exclusion of java.util.concurrent.locks.AbstractOwnableSynchronizer.setExclusiveOwnerThread() /* The exclusion of java.util.concurrent.locks.AbstractOwnableSynchronizer.setExclusiveOwnerThread()
@ -161,6 +160,7 @@ public class ReservedStackTest {
} catch (StackOverflowError e) { } catch (StackOverflowError e) {
soe = e; soe = e;
stackOverflowErrorReceived = true; stackOverflowErrorReceived = true;
throw e;
} }
} }
@ -194,13 +194,10 @@ public class ReservedStackTest {
decounter = deframe; decounter = deframe;
test.initialize(); test.initialize();
recursiveCall(); recursiveCall();
System.out.println("Framework got StackOverflowError at frame = " + counter);
System.out.println("Test started execution at frame = " + (counter - deframe));
String result = test.getResult(); String result = test.getResult();
// The feature is not fully implemented on all platforms, // The feature is not fully implemented on all platforms,
// corruptions are still possible. // corruptions are still possible.
if (isSupportedPlatform && !result.contains("PASSED")) { if (isSupportedPlatform && !result.contains("PASSED")) {
System.out.println(result);
throw new Error(result); throw new Error(result);
} else { } else {
// Either the test passed or this platform is not supported. // Either the test passed or this platform is not supported.
@ -289,7 +286,7 @@ public class ReservedStackTest {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
initIsSupportedPlatform(); initIsSupportedPlatform();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 100; i++) {
// Each iteration has to be executed by a new thread. The test // Each iteration has to be executed by a new thread. The test
// relies on the random size area pushed by the VM at the beginning // relies on the random size area pushed by the VM at the beginning
// of the stack of each Java thread it creates. // of the stack of each Java thread it creates.