# HG changeset patch # User mdoerr # Date 1459513453 -7200 # Node ID ccd5cb447428181783d2c42e52ca1a91b7a3e6c2 # Parent fdc0e7bfa03be7fe3d31e8c87d20e96b43792413 8153267: nmethod's exception cache not multi-thread safe Reviewed-by: diff --git a/src/share/vm/code/nmethod.cpp b/src/share/vm/code/nmethod.cpp --- a/src/share/vm/code/nmethod.cpp +++ b/src/share/vm/code/nmethod.cpp @@ -441,10 +441,11 @@ assert(new_entry != NULL,"Must be non null"); assert(new_entry->next() == NULL, "Must be null"); - if (exception_cache() != NULL) { - new_entry->set_next(exception_cache()); + ExceptionCache *ec = exception_cache(); + if (ec != NULL) { + new_entry->set_next(ec); } - set_exception_cache(new_entry); + release_set_exception_cache(new_entry); } void nmethod::clean_exception_cache(BoolObjectClosure* is_alive) { diff --git a/src/share/vm/code/nmethod.hpp b/src/share/vm/code/nmethod.hpp --- a/src/share/vm/code/nmethod.hpp +++ b/src/share/vm/code/nmethod.hpp @@ -241,7 +241,7 @@ // counter is decreased (by 1) while sweeping. int _hotness_counter; - ExceptionCache *_exception_cache; + ExceptionCache * volatile _exception_cache; PcDescCache _pc_desc_cache; // These are used for compiled synchronized native methods to @@ -433,7 +433,7 @@ // flag accessing and manipulation bool is_in_use() const { return _state == in_use; } - bool is_alive() const { return _state == in_use || _state == not_entrant; } + bool is_alive() const { unsigned char s = _state; return s == in_use || s == not_entrant; } bool is_not_entrant() const { return _state == not_entrant; } bool is_zombie() const { return _state == zombie; } bool is_unloaded() const { return _state == unloaded; } @@ -578,6 +578,7 @@ // Exception cache support ExceptionCache* exception_cache() const { return _exception_cache; } void set_exception_cache(ExceptionCache *ec) { _exception_cache = ec; } + void release_set_exception_cache(ExceptionCache *ec) { OrderAccess::release_store_ptr(&_exception_cache, ec); } address handler_for_exception_and_pc(Handle exception, address pc); void add_handler_for_exception_and_pc(Handle exception, address pc, address handler); void clean_exception_cache(BoolObjectClosure* is_alive); diff --git a/src/share/vm/runtime/vmStructs.cpp b/src/share/vm/runtime/vmStructs.cpp --- a/src/share/vm/runtime/vmStructs.cpp +++ b/src/share/vm/runtime/vmStructs.cpp @@ -959,7 +959,7 @@ nonstatic_field(nmethod, _stack_traversal_mark, long) \ nonstatic_field(nmethod, _compile_id, int) \ nonstatic_field(nmethod, _comp_level, int) \ - nonstatic_field(nmethod, _exception_cache, ExceptionCache*) \ + volatile_nonstatic_field(nmethod, _exception_cache, ExceptionCache*) \ \ unchecked_c2_static_field(Deoptimization, _trap_reason_name, void*) \ \