Skip to content
Permalink
Browse files
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 1e570870f21046b7216987a6de68e6d9ac09c1be
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
@@ -299,7 +299,7 @@ bool ciMethod::has_balanced_monitors() {
}

{
EXCEPTION_MARK;
ExceptionMark em(THREAD);
ResourceMark rm(THREAD);
GeneratePairingInfo gpi(method);
gpi.compute_map(CATCH);
@@ -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 ) {
@@ -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);
@@ -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,
@@ -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();
@@ -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) {
@@ -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()) {
@@ -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
@@ -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,
@@ -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
@@ -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
@@ -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

0 comments on commit 1e57087

Please sign in to comment.