Skip to content

Commit 1e57087

Browse files
committed
8263392: Allow current thread to be specified in ExceptionMark
Reviewed-by: dholmes, ccheung, coleenp, minqi
1 parent 4d1c08c commit 1e57087

File tree

8 files changed

+31
-18
lines changed

8 files changed

+31
-18
lines changed

src/hotspot/share/ci/ciMethod.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ bool ciMethod::has_balanced_monitors() {
299299
}
300300

301301
{
302-
EXCEPTION_MARK;
302+
ExceptionMark em(THREAD);
303303
ResourceMark rm(THREAD);
304304
GeneratePairingInfo gpi(method);
305305
gpi.compute_map(CATCH);
@@ -1143,7 +1143,7 @@ bool ciMethod::was_executed_more_than(int times) {
11431143
bool ciMethod::has_unloaded_classes_in_signature() {
11441144
VM_ENTRY_MARK;
11451145
{
1146-
EXCEPTION_MARK;
1146+
ExceptionMark em(THREAD);
11471147
methodHandle m(THREAD, get_Method());
11481148
bool has_unloaded = Method::has_unloaded_classes_in_signature(m, thread);
11491149
if( HAS_PENDING_EXCEPTION ) {
@@ -1170,7 +1170,7 @@ bool ciMethod::check_call(int refinfo_index, bool is_static) const {
11701170
// FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points.
11711171
VM_ENTRY_MARK;
11721172
{
1173-
EXCEPTION_MARK;
1173+
ExceptionMark em(THREAD);
11741174
HandleMark hm(THREAD);
11751175
constantPoolHandle pool (THREAD, get_Method()->constants());
11761176
Bytecodes::Code code = (is_static ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual);

src/hotspot/share/classfile/javaClasses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ void java_lang_Throwable::print_stack_trace(Handle throwable, outputStream* st)
23822382
}
23832383
{
23842384
// Call getCause() which doesn't necessarily return the _cause field.
2385-
EXCEPTION_MARK;
2385+
ExceptionMark em(THREAD);
23862386
JavaValue cause(T_OBJECT);
23872387
JavaCalls::call_virtual(&cause,
23882388
throwable,

src/hotspot/share/memory/universe.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ void Universe::fixup_mirrors(TRAPS) {
475475
for (int i = 0; i < list_length; i++) {
476476
Klass* k = list->at(i);
477477
assert(k->is_klass(), "List should only hold classes");
478-
EXCEPTION_MARK;
479478
java_lang_Class::fixup_mirror(k, CATCH);
480479
}
481480
delete java_lang_Class::fixup_mirror_list();

src/hotspot/share/oops/constantPool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int w
603603
// Avoid constant pool verification at a safepoint, which takes the Module_lock.
604604
if (k != NULL && !SafepointSynchronize::is_at_safepoint()) {
605605
// Make sure that resolving is legal
606-
EXCEPTION_MARK;
606+
ExceptionMark em(thread);
607+
Thread* THREAD = thread; // For exception macros.
607608
// return NULL if verification fails
608609
verify_constant_pool_resolve(this_cp, k, THREAD);
609610
if (HAS_PENDING_EXCEPTION) {

src/hotspot/share/runtime/sharedRuntime.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,10 +2132,10 @@ JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* obj, Ba
21322132
SharedRuntime::monitor_enter_helper(obj, lock, thread);
21332133
JRT_END
21342134

2135-
void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread) {
2136-
assert(JavaThread::current() == thread, "invariant");
2135+
void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current) {
2136+
assert(JavaThread::current() == current, "invariant");
21372137
// Exit must be non-blocking, and therefore no exceptions can be thrown.
2138-
EXCEPTION_MARK;
2138+
ExceptionMark em(current);
21392139
// The object could become unlocked through a JNI call, which we have no other checks for.
21402140
// Give a fatal message if CheckJNICalls. Otherwise we ignore it.
21412141
if (obj->is_unlocked()) {
@@ -2144,7 +2144,7 @@ void SharedRuntime::monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThrea
21442144
}
21452145
return;
21462146
}
2147-
ObjectSynchronizer::exit(obj, lock, thread);
2147+
ObjectSynchronizer::exit(obj, lock, current);
21482148
}
21492149

21502150
// Handles the uncommon cases of monitor unlocking in compiled code

src/hotspot/share/runtime/sharedRuntime.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class SharedRuntime: AllStatic {
343343

344344
static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
345345

346-
static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
346+
static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
347347

348348
private:
349349
static Handle find_callee_info(JavaThread* thread,

src/hotspot/share/utilities/exceptions.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,18 @@ void Exceptions::print_exception_counts_on_error(outputStream* st) {
499499

500500
// Implementation of ExceptionMark
501501

502-
ExceptionMark::ExceptionMark(Thread*& thread) {
503-
thread = Thread::current();
504-
_thread = thread;
502+
ExceptionMark::ExceptionMark(Thread* thread) {
503+
assert(thread == Thread::current(), "must be");
504+
_thread = thread;
505+
check_no_pending_exception();
506+
}
507+
508+
ExceptionMark::ExceptionMark() {
509+
_thread = Thread::current();
510+
check_no_pending_exception();
511+
}
512+
513+
inline void ExceptionMark::check_no_pending_exception() {
505514
if (_thread->has_pending_exception()) {
506515
oop exception = _thread->pending_exception();
507516
_thread->clear_pending_exception(); // Needed to avoid infinite recursion

src/hotspot/share/utilities/exceptions.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,17 @@ class Exceptions {
331331
class ExceptionMark {
332332
private:
333333
Thread* _thread;
334+
inline void check_no_pending_exception();
334335

335336
public:
336-
ExceptionMark(Thread*& thread);
337+
ExceptionMark();
338+
ExceptionMark(Thread* thread);
337339
~ExceptionMark();
338-
};
339-
340340

341+
Thread* thread() {
342+
return _thread;
343+
}
344+
};
341345

342346
// Use an EXCEPTION_MARK for 'local' exceptions. EXCEPTION_MARK makes sure that no
343347
// pending exception exists upon entering its scope and tests that no pending exception
@@ -347,6 +351,6 @@ class ExceptionMark {
347351
// which preserves pre-existing exceptions and does not allow new
348352
// exceptions.
349353

350-
#define EXCEPTION_MARK Thread* THREAD = NULL; ExceptionMark __em(THREAD);
354+
#define EXCEPTION_MARK ExceptionMark __em; Thread* THREAD = __em.thread();
351355

352356
#endif // SHARE_UTILITIES_EXCEPTIONS_HPP

0 commit comments

Comments
 (0)