Skip to content

Commit d35c154

Browse files
committed
8227766: CheckUnhandledOops is broken in MemAllocator
Save oop created in handle more eagerly, so CheckUnhandledOops doesn't bash it. Reviewed-by: lfoltan, eosterlund
1 parent d97475d commit d35c154

File tree

6 files changed

+65
-19
lines changed

6 files changed

+65
-19
lines changed

src/hotspot/share/classfile/stringTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ oop StringTable::intern(Handle string_or_null_h, const jchar* name, int len, TRA
342342
if (found_string != NULL) {
343343
return found_string;
344344
}
345-
return do_intern(string_or_null_h, name, len, hash, CHECK_NULL);
345+
return do_intern(string_or_null_h, name, len, hash, THREAD);
346346
}
347347

348348
oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,

src/hotspot/share/gc/shared/memAllocator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ oop MemAllocator::allocate() const {
370370
HeapWord* mem = mem_allocate(allocation);
371371
if (mem != NULL) {
372372
obj = initialize(mem);
373+
} else {
374+
// The unhandled oop detector will poison local variable obj,
375+
// so reset it to NULL if mem is NULL.
376+
obj = NULL;
373377
}
374378
}
375379
return obj;

src/hotspot/share/runtime/javaCalls.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -346,9 +346,6 @@ void JavaCalls::call_helper(JavaValue* result, const methodHandle& method, JavaC
346346
assert(!SafepointSynchronize::is_at_safepoint(), "call to Java code during VM operation");
347347
assert(!thread->handle_area()->no_handle_mark_active(), "cannot call out to Java here");
348348

349-
350-
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();)
351-
352349
#if INCLUDE_JVMCI
353350
// Gets the nmethod (if any) that should be called instead of normal target
354351
nmethod* alternative_target = args->alternative_target();
@@ -395,10 +392,6 @@ void JavaCalls::call_helper(JavaValue* result, const methodHandle& method, JavaC
395392
BasicType result_type = runtime_type_from(result);
396393
bool oop_result_flag = (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY);
397394

398-
// NOTE: if we move the computation of the result_val_address inside
399-
// the call to call_stub, the optimizer produces wrong code.
400-
intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
401-
402395
// Find receiver
403396
Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
404397

@@ -436,14 +429,19 @@ void JavaCalls::call_helper(JavaValue* result, const methodHandle& method, JavaC
436429
{ JavaCallWrapper link(method, receiver, result, CHECK);
437430
{ HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
438431

432+
// NOTE: if we move the computation of the result_val_address inside
433+
// the call to call_stub, the optimizer produces wrong code.
434+
intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
435+
intptr_t* parameter_address = args->parameters();
436+
439437
StubRoutines::call_stub()(
440438
(address)&link,
441439
// (intptr_t*)&(result->_value), // see NOTE above (compiler problem)
442440
result_val_address, // see NOTE above (compiler problem)
443441
result_type,
444442
method(),
445443
entry_point,
446-
args->parameters(),
444+
parameter_address,
447445
args->size_of_parameters(),
448446
CHECK
449447
);

src/hotspot/share/runtime/unhandledOops.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,15 +55,15 @@ void UnhandledOops::dump_oops(UnhandledOops *list) {
5555

5656
// For debugging unhandled oop detector _in the debugger_
5757
// You don't want to turn it on in compiled code here.
58-
static bool unhandled_oop_print=0;
58+
static Thread* unhandled_oop_print = NULL;
5959

6060
void UnhandledOops::register_unhandled_oop(oop* op, address pc) {
6161
if (!_thread->is_in_stack((address)op))
6262
return;
6363

64-
_level ++;
65-
if (unhandled_oop_print) {
66-
for (int i=0; i<_level; i++) tty->print(" ");
64+
_level++;
65+
if (unhandled_oop_print == _thread) {
66+
for (int i=0; i < _level; i++) tty->print(" ");
6767
tty->print_cr("r " INTPTR_FORMAT, p2i(op));
6868
}
6969
UnhandledOopEntry entry(op, pc);
@@ -98,11 +98,11 @@ void UnhandledOops::allow_unhandled_oop(oop* op) {
9898
void UnhandledOops::unregister_unhandled_oop(oop* op) {
9999
if (!_thread->is_in_stack((address)op)) return;
100100

101-
_level --;
102-
if (unhandled_oop_print) {
103-
for (int i=0; i<_level; i++) tty->print(" ");
101+
if (unhandled_oop_print == _thread) {
102+
for (int i=0; i < _level; i++) tty->print(" ");
104103
tty->print_cr("u " INTPTR_FORMAT, p2i(op));
105104
}
105+
_level--;
106106

107107
int i = _oop_list->find_from_end(op, match_oop_entry);
108108
assert(i!=-1, "oop not in unhandled_oop_list");

src/hotspot/share/services/gcNotifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static Handle createGcInfo(GCMemoryManager *gcManager, GCStatInfo *gcStatInfo,TR
159159
gcInfoklass,
160160
vmSymbols::com_sun_management_GcInfo_constructor_signature(),
161161
&constructor_args,
162-
CHECK_NH);
162+
THREAD);
163163
}
164164

165165
void GCNotifier::sendNotification(TRAPS) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8227766
27+
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+CheckUnhandledOops -Xmx100m TestOutOfMemory
28+
*/
29+
30+
public class TestOutOfMemory {
31+
public static void main(java.lang.String[] unused) {
32+
final int BIG = 0x100000;
33+
// Getting OOM breaks the unhandled oop detector
34+
try {
35+
int[][] X = new int[BIG][];
36+
for (int i = 0; i < BIG; i++) {
37+
X[i] = new int[BIG];
38+
System.out.println("length = " + X.length);
39+
}
40+
} catch (OutOfMemoryError oom) {
41+
System.out.println("OOM expected");
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)