--- old/src/share/vm/compiler/compileBroker.cpp 2014-09-17 16:06:58.000000000 -0700 +++ new/src/share/vm/compiler/compileBroker.cpp 2014-09-17 16:06:58.000000000 -0700 @@ -1206,6 +1206,12 @@ return; } + if (TieredCompilation) { + // Tiered policy requires MethodCounters to exist before adding a method to + // the queue. Create if we don't have them yet. + method->get_method_counters(thread); + } + // Outputs from the following MutexLocker block: CompileTask* task = NULL; bool blocking = false; --- old/src/share/vm/oops/method.cpp 2014-09-17 16:06:58.000000000 -0700 +++ new/src/share/vm/oops/method.cpp 2014-09-17 16:06:58.000000000 -0700 @@ -395,9 +395,7 @@ methodHandle mh(m); ClassLoaderData* loader_data = mh->method_holder()->class_loader_data(); MethodCounters* counters = MethodCounters::allocate(loader_data, CHECK_NULL); - if (mh->method_counters() == NULL) { - mh->set_method_counters(counters); - } else { + if (!mh->init_method_counters(counters)) { MetadataFactory::free_metadata(loader_data, counters); } return mh->method_counters(); --- old/src/share/vm/oops/method.hpp 2014-09-17 16:06:58.000000000 -0700 +++ new/src/share/vm/oops/method.hpp 2014-09-17 16:06:58.000000000 -0700 @@ -340,6 +340,11 @@ OrderAccess::release_store_ptr((volatile void *)&_method_counters, counters); } + bool init_method_counters(MethodCounters* counters) { + // Try to install a pointer to MethodCounters, return true on success. + return Atomic::cmpxchg_ptr(counters, (volatile void*)&_method_counters, NULL) == NULL; + } + #ifdef TIERED // We are reusing interpreter_invocation_count as a holder for the previous event count! // We can do that since interpreter_invocation_count is not used in tiered.