Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8263392: Allow current thread to be specified in ExceptionMark
Reviewed-by: dholmes, ccheung, coleenp, minqi
  • Loading branch information
iklam committed Mar 15, 2021
1 parent 4d1c08c commit 1e57087
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/hotspot/share/ci/ciMethod.cpp
Expand Up @@ -299,7 +299,7 @@ bool ciMethod::has_balanced_monitors() {
}

{
EXCEPTION_MARK;
ExceptionMark em(THREAD);
ResourceMark rm(THREAD);
GeneratePairingInfo gpi(method);
gpi.compute_map(CATCH);
Expand Down Expand Up @@ -1143,7 +1143,7 @@ bool ciMethod::was_executed_more_than(int times) {
bool ciMethod::has_unloaded_classes_in_signature() {
VM_ENTRY_MARK;
{
EXCEPTION_MARK;
ExceptionMark em(THREAD);
methodHandle m(THREAD, get_Method());
bool has_unloaded = Method::has_unloaded_classes_in_signature(m, thread);
if( HAS_PENDING_EXCEPTION ) {
Expand All @@ -1170,7 +1170,7 @@ bool ciMethod::check_call(int refinfo_index, bool is_static) const {
// FIXME: Remove this method and resolve_method_statically; refactor to use the other LinkResolver entry points.
VM_ENTRY_MARK;
{
EXCEPTION_MARK;
ExceptionMark em(THREAD);
HandleMark hm(THREAD);
constantPoolHandle pool (THREAD, get_Method()->constants());
Bytecodes::Code code = (is_static ? Bytecodes::_invokestatic : Bytecodes::_invokevirtual);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/javaClasses.cpp
Expand Up @@ -2382,7 +2382,7 @@ void java_lang_Throwable::print_stack_trace(Handle throwable, outputStream* st)
}
{
// Call getCause() which doesn't necessarily return the _cause field.
EXCEPTION_MARK;
ExceptionMark em(THREAD);
JavaValue cause(T_OBJECT);
JavaCalls::call_virtual(&cause,
throwable,
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/memory/universe.cpp
Expand Up @@ -475,7 +475,6 @@ void Universe::fixup_mirrors(TRAPS) {
for (int i = 0; i < list_length; i++) {
Klass* k = list->at(i);
assert(k->is_klass(), "List should only hold classes");
EXCEPTION_MARK;
java_lang_Class::fixup_mirror(k, CATCH);
}
delete java_lang_Class::fixup_mirror_list();
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/oops/constantPool.cpp
Expand Up @@ -603,7 +603,8 @@ Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int w
// Avoid constant pool verification at a safepoint, which takes the Module_lock.
if (k != NULL && !SafepointSynchronize::is_at_safepoint()) {
// Make sure that resolving is legal
EXCEPTION_MARK;
ExceptionMark em(thread);
Thread* THREAD = thread; // For exception macros.
// return NULL if verification fails
verify_constant_pool_resolve(this_cp, k, THREAD);
if (HAS_PENDING_EXCEPTION) {
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/runtime/sharedRuntime.cpp
Expand Up @@ -2132,10 +2132,10 @@ JRT_BLOCK_ENTRY(void, SharedRuntime::complete_monitor_locking_C(oopDesc* obj, Ba
SharedRuntime::monitor_enter_helper(obj, lock, thread);
JRT_END

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

// Handles the uncommon cases of monitor unlocking in compiled code
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/runtime/sharedRuntime.hpp
Expand Up @@ -343,7 +343,7 @@ class SharedRuntime: AllStatic {

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

static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);

private:
static Handle find_callee_info(JavaThread* thread,
Expand Down
15 changes: 12 additions & 3 deletions src/hotspot/share/utilities/exceptions.cpp
Expand Up @@ -499,9 +499,18 @@ void Exceptions::print_exception_counts_on_error(outputStream* st) {

// Implementation of ExceptionMark

ExceptionMark::ExceptionMark(Thread*& thread) {
thread = Thread::current();
_thread = thread;
ExceptionMark::ExceptionMark(Thread* thread) {
assert(thread == Thread::current(), "must be");
_thread = thread;
check_no_pending_exception();
}

ExceptionMark::ExceptionMark() {
_thread = Thread::current();
check_no_pending_exception();
}

inline void ExceptionMark::check_no_pending_exception() {
if (_thread->has_pending_exception()) {
oop exception = _thread->pending_exception();
_thread->clear_pending_exception(); // Needed to avoid infinite recursion
Expand Down
12 changes: 8 additions & 4 deletions src/hotspot/share/utilities/exceptions.hpp
Expand Up @@ -331,13 +331,17 @@ class Exceptions {
class ExceptionMark {
private:
Thread* _thread;
inline void check_no_pending_exception();

public:
ExceptionMark(Thread*& thread);
ExceptionMark();
ExceptionMark(Thread* thread);
~ExceptionMark();
};


Thread* thread() {
return _thread;
}
};

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

#define EXCEPTION_MARK Thread* THREAD = NULL; ExceptionMark __em(THREAD);
#define EXCEPTION_MARK ExceptionMark __em; Thread* THREAD = __em.thread();

#endif // SHARE_UTILITIES_EXCEPTIONS_HPP

1 comment on commit 1e57087

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.