src/share/vm/memory/universe.inline.hpp

Print this page

        

*** 24,33 **** --- 24,34 ---- #ifndef SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP #define SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP #include "memory/universe.hpp" + #include "runtime/atomic.hpp" // Check whether an element of a typeArrayOop with the given type must be // aligned 0 mod 8. The typeArrayOop itself must be aligned at least this // strongly.
*** 39,44 **** --- 40,88 ---- inline bool Universe::field_type_should_be_aligned(BasicType type) { return type == T_DOUBLE || type == T_LONG; } + + // Helper methods to cache the first user class loader + + inline oop Universe::get_cached_loader() { + return _primordial_loader_cache; + } + + inline bool Universe::check_or_set_cached_loader(oop loader) { + // System loader is null or cache is already invalidated stop here + if (loader == NULL || (_primordial_loader_cache == (void*) -1)) { + return false; + } + + // atomically set _primordial_loader_cache + void* old = Atomic::cmpxchg_ptr((void *)loader, (void*)&_primordial_loader_cache, (void *)NULL); + if (old != NULL) { + // loader must have already been set, is it the same loader on another thread? + if (loader == old) { + // Yes it's the same loader + #ifdef ASSERT + tty->print("FOUND SAME IN LDR CACHE was " INTPTR_FORMAT "\n", old); + #endif + return false; + } else if (old != (void*) -1) { + // No, we must have more than 1 user class loader, so shut off the cache + Atomic::store_ptr((void*) -1, (void*)&_primordial_loader_cache); + #ifdef ASSERT + tty->print("CLEARED LDR CACHE was " INTPTR_FORMAT " curr " INTPTR_FORMAT"\n", old, loader); + #endif + return false; + } else { + // Already cleared + return false; + } + } + + // We won to set the cache + #ifdef ASSERT + tty->print("SET LDR CACHE to " INTPTR_FORMAT"\n", loader); + #endif + return true; + } + #endif // SHARE_VM_MEMORY_UNIVERSE_INLINE_HPP