0N/A/*
3157N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "code/codeCache.hpp"
1879N/A#include "code/compiledIC.hpp"
2677N/A#include "code/dependencies.hpp"
1879N/A#include "code/nmethod.hpp"
1879N/A#include "code/scopeDesc.hpp"
1879N/A#include "compiler/abstractCompiler.hpp"
2252N/A#include "compiler/compileBroker.hpp"
1879N/A#include "compiler/compileLog.hpp"
1879N/A#include "compiler/compilerOracle.hpp"
1879N/A#include "compiler/disassembler.hpp"
1879N/A#include "interpreter/bytecode.hpp"
1879N/A#include "oops/methodDataOop.hpp"
1879N/A#include "prims/jvmtiRedefineClassesTrace.hpp"
2076N/A#include "prims/jvmtiImpl.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/sweeper.hpp"
1879N/A#include "utilities/dtrace.hpp"
1879N/A#include "utilities/events.hpp"
1879N/A#include "utilities/xmlstream.hpp"
1879N/A#ifdef SHARK
1879N/A#include "shark/sharkCompiler.hpp"
1879N/A#endif
0N/A
0N/A#ifdef DTRACE_ENABLED
0N/A
0N/A// Only bother with this argument setup if dtrace is available
0N/A
2842N/A#ifndef USDT2
0N/AHS_DTRACE_PROBE_DECL8(hotspot, compiled__method__load,
0N/A const char*, int, const char*, int, const char*, int, void*, size_t);
0N/A
0N/AHS_DTRACE_PROBE_DECL6(hotspot, compiled__method__unload,
0N/A char*, int, char*, int, char*, int);
0N/A
0N/A#define DTRACE_METHOD_UNLOAD_PROBE(method) \
0N/A { \
0N/A methodOop m = (method); \
0N/A if (m != NULL) { \
2062N/A Symbol* klass_name = m->klass_name(); \
2062N/A Symbol* name = m->name(); \
2062N/A Symbol* signature = m->signature(); \
0N/A HS_DTRACE_PROBE6(hotspot, compiled__method__unload, \
0N/A klass_name->bytes(), klass_name->utf8_length(), \
0N/A name->bytes(), name->utf8_length(), \
0N/A signature->bytes(), signature->utf8_length()); \
0N/A } \
0N/A }
2842N/A#else /* USDT2 */
2842N/A#define DTRACE_METHOD_UNLOAD_PROBE(method) \
2842N/A { \
2842N/A methodOop m = (method); \
2842N/A if (m != NULL) { \
2842N/A Symbol* klass_name = m->klass_name(); \
2842N/A Symbol* name = m->name(); \
2842N/A Symbol* signature = m->signature(); \
2842N/A HOTSPOT_COMPILED_METHOD_UNLOAD( \
2842N/A (char *) klass_name->bytes(), klass_name->utf8_length(), \
2842N/A (char *) name->bytes(), name->utf8_length(), \
2842N/A (char *) signature->bytes(), signature->utf8_length()); \
2842N/A } \
2842N/A }
2842N/A#endif /* USDT2 */
0N/A
0N/A#else // ndef DTRACE_ENABLED
0N/A
0N/A#define DTRACE_METHOD_UNLOAD_PROBE(method)
0N/A
0N/A#endif
0N/A
0N/Abool nmethod::is_compiled_by_c1() const {
1155N/A if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing
0N/A if (is_native_method()) return false;
0N/A return compiler()->is_c1();
0N/A}
0N/Abool nmethod::is_compiled_by_c2() const {
1155N/A if (compiler() == NULL || method() == NULL) return false; // can happen during debug printing
0N/A if (is_native_method()) return false;
0N/A return compiler()->is_c2();
0N/A}
1612N/Abool nmethod::is_compiled_by_shark() const {
1612N/A if (is_native_method()) return false;
1612N/A assert(compiler() != NULL, "must be");
1612N/A return compiler()->is_shark();
1612N/A}
0N/A
0N/A
0N/A
0N/A//---------------------------------------------------------------------------------
0N/A// NMethod statistics
0N/A// They are printed under various flags, including:
0N/A// PrintC1Statistics, PrintOptoStatistics, LogVMOutput, and LogCompilation.
0N/A// (In the latter two cases, they like other stats are printed to the log only.)
0N/A
0N/A#ifndef PRODUCT
0N/A// These variables are put into one block to reduce relocations
0N/A// and make it simpler to print from the debugger.
0N/Astatic
0N/Astruct nmethod_stats_struct {
0N/A int nmethod_count;
0N/A int total_size;
0N/A int relocation_size;
1682N/A int consts_size;
1668N/A int insts_size;
0N/A int stub_size;
0N/A int scopes_data_size;
0N/A int scopes_pcs_size;
0N/A int dependencies_size;
0N/A int handler_table_size;
0N/A int nul_chk_table_size;
0N/A int oops_size;
0N/A
0N/A void note_nmethod(nmethod* nm) {
0N/A nmethod_count += 1;
0N/A total_size += nm->size();
0N/A relocation_size += nm->relocation_size();
1682N/A consts_size += nm->consts_size();
1668N/A insts_size += nm->insts_size();
0N/A stub_size += nm->stub_size();
1483N/A oops_size += nm->oops_size();
0N/A scopes_data_size += nm->scopes_data_size();
0N/A scopes_pcs_size += nm->scopes_pcs_size();
0N/A dependencies_size += nm->dependencies_size();
0N/A handler_table_size += nm->handler_table_size();
0N/A nul_chk_table_size += nm->nul_chk_table_size();
0N/A }
0N/A void print_nmethod_stats() {
0N/A if (nmethod_count == 0) return;
0N/A tty->print_cr("Statistics for %d bytecoded nmethods:", nmethod_count);
0N/A if (total_size != 0) tty->print_cr(" total in heap = %d", total_size);
0N/A if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size);
1682N/A if (consts_size != 0) tty->print_cr(" constants = %d", consts_size);
1668N/A if (insts_size != 0) tty->print_cr(" main code = %d", insts_size);
0N/A if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size);
1483N/A if (oops_size != 0) tty->print_cr(" oops = %d", oops_size);
0N/A if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size);
0N/A if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size);
0N/A if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size);
0N/A if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size);
0N/A if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size);
0N/A }
0N/A
0N/A int native_nmethod_count;
0N/A int native_total_size;
0N/A int native_relocation_size;
1668N/A int native_insts_size;
0N/A int native_oops_size;
0N/A void note_native_nmethod(nmethod* nm) {
0N/A native_nmethod_count += 1;
0N/A native_total_size += nm->size();
0N/A native_relocation_size += nm->relocation_size();
1668N/A native_insts_size += nm->insts_size();
0N/A native_oops_size += nm->oops_size();
0N/A }
0N/A void print_native_nmethod_stats() {
0N/A if (native_nmethod_count == 0) return;
0N/A tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count);
0N/A if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size);
0N/A if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size);
1668N/A if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size);
0N/A if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size);
0N/A }
0N/A
0N/A int pc_desc_resets; // number of resets (= number of caches)
0N/A int pc_desc_queries; // queries to nmethod::find_pc_desc
0N/A int pc_desc_approx; // number of those which have approximate true
2186N/A int pc_desc_repeats; // number of _pc_descs[0] hits
0N/A int pc_desc_hits; // number of LRU cache hits
0N/A int pc_desc_tests; // total number of PcDesc examinations
0N/A int pc_desc_searches; // total number of quasi-binary search steps
0N/A int pc_desc_adds; // number of LUR cache insertions
0N/A
0N/A void print_pc_stats() {
0N/A tty->print_cr("PcDesc Statistics: %d queries, %.2f comparisons per query",
0N/A pc_desc_queries,
0N/A (double)(pc_desc_tests + pc_desc_searches)
0N/A / pc_desc_queries);
0N/A tty->print_cr(" caches=%d queries=%d/%d, hits=%d+%d, tests=%d+%d, adds=%d",
0N/A pc_desc_resets,
0N/A pc_desc_queries, pc_desc_approx,
0N/A pc_desc_repeats, pc_desc_hits,
0N/A pc_desc_tests, pc_desc_searches, pc_desc_adds);
0N/A }
0N/A} nmethod_stats;
0N/A#endif //PRODUCT
0N/A
2168N/A
0N/A//---------------------------------------------------------------------------------
0N/A
0N/A
0N/AExceptionCache::ExceptionCache(Handle exception, address pc, address handler) {
0N/A assert(pc != NULL, "Must be non null");
0N/A assert(exception.not_null(), "Must be non null");
0N/A assert(handler != NULL, "Must be non null");
0N/A
0N/A _count = 0;
0N/A _exception_type = exception->klass();
0N/A _next = NULL;
0N/A
0N/A add_address_and_handler(pc,handler);
0N/A}
0N/A
0N/A
0N/Aaddress ExceptionCache::match(Handle exception, address pc) {
0N/A assert(pc != NULL,"Must be non null");
0N/A assert(exception.not_null(),"Must be non null");
0N/A if (exception->klass() == exception_type()) {
0N/A return (test_address(pc));
0N/A }
0N/A
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/Abool ExceptionCache::match_exception_with_space(Handle exception) {
0N/A assert(exception.not_null(),"Must be non null");
0N/A if (exception->klass() == exception_type() && count() < cache_size) {
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A
0N/Aaddress ExceptionCache::test_address(address addr) {
0N/A for (int i=0; i<count(); i++) {
0N/A if (pc_at(i) == addr) {
0N/A return handler_at(i);
0N/A }
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/Abool ExceptionCache::add_address_and_handler(address addr, address handler) {
0N/A if (test_address(addr) == handler) return true;
0N/A if (count() < cache_size) {
0N/A set_pc_at(count(),addr);
0N/A set_handler_at(count(), handler);
0N/A increment_count();
0N/A return true;
0N/A }
0N/A return false;
0N/A}
0N/A
0N/A
0N/A// private method for handling exception cache
0N/A// These methods are private, and used to manipulate the exception cache
0N/A// directly.
0N/AExceptionCache* nmethod::exception_cache_entry_for_exception(Handle exception) {
0N/A ExceptionCache* ec = exception_cache();
0N/A while (ec != NULL) {
0N/A if (ec->match_exception_with_space(exception)) {
0N/A return ec;
0N/A }
0N/A ec = ec->next();
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A
0N/A
0N/A// Helper used by both find_pc_desc methods.
0N/Astatic inline bool match_desc(PcDesc* pc, int pc_offset, bool approximate) {
0N/A NOT_PRODUCT(++nmethod_stats.pc_desc_tests);
0N/A if (!approximate)
0N/A return pc->pc_offset() == pc_offset;
0N/A else
0N/A return (pc-1)->pc_offset() < pc_offset && pc_offset <= pc->pc_offset();
0N/A}
0N/A
0N/Avoid PcDescCache::reset_to(PcDesc* initial_pc_desc) {
0N/A if (initial_pc_desc == NULL) {
2186N/A _pc_descs[0] = NULL; // native method; no PcDescs at all
0N/A return;
0N/A }
0N/A NOT_PRODUCT(++nmethod_stats.pc_desc_resets);
0N/A // reset the cache by filling it with benign (non-null) values
0N/A assert(initial_pc_desc->pc_offset() < 0, "must be sentinel");
0N/A for (int i = 0; i < cache_size; i++)
0N/A _pc_descs[i] = initial_pc_desc;
0N/A}
0N/A
0N/APcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) {
0N/A NOT_PRODUCT(++nmethod_stats.pc_desc_queries);
2186N/A NOT_PRODUCT(if (approximate) ++nmethod_stats.pc_desc_approx);
2186N/A
2186N/A // Note: one might think that caching the most recently
2186N/A // read value separately would be a win, but one would be
2186N/A // wrong. When many threads are updating it, the cache
2186N/A // line it's in would bounce between caches, negating
2186N/A // any benefit.
0N/A
0N/A // In order to prevent race conditions do not load cache elements
0N/A // repeatedly, but use a local copy:
0N/A PcDesc* res;
0N/A
2186N/A // Step one: Check the most recently added value.
2186N/A res = _pc_descs[0];
2186N/A if (res == NULL) return NULL; // native method; no PcDescs at all
0N/A if (match_desc(res, pc_offset, approximate)) {
0N/A NOT_PRODUCT(++nmethod_stats.pc_desc_repeats);
0N/A return res;
0N/A }
0N/A
2186N/A // Step two: Check the rest of the LRU cache.
2186N/A for (int i = 1; i < cache_size; ++i) {
0N/A res = _pc_descs[i];
2186N/A if (res->pc_offset() < 0) break; // optimization: skip empty cache
0N/A if (match_desc(res, pc_offset, approximate)) {
0N/A NOT_PRODUCT(++nmethod_stats.pc_desc_hits);
0N/A return res;
0N/A }
0N/A }
0N/A
0N/A // Report failure.
0N/A return NULL;
0N/A}
0N/A
0N/Avoid PcDescCache::add_pc_desc(PcDesc* pc_desc) {
0N/A NOT_PRODUCT(++nmethod_stats.pc_desc_adds);
2186N/A // Update the LRU cache by shifting pc_desc forward.
0N/A for (int i = 0; i < cache_size; i++) {
0N/A PcDesc* next = _pc_descs[i];
0N/A _pc_descs[i] = pc_desc;
0N/A pc_desc = next;
0N/A }
0N/A}
0N/A
0N/A// adjust pcs_size so that it is a multiple of both oopSize and
0N/A// sizeof(PcDesc) (assumes that if sizeof(PcDesc) is not a multiple
0N/A// of oopSize, then 2*sizeof(PcDesc) is)
2186N/Astatic int adjust_pcs_size(int pcs_size) {
0N/A int nsize = round_to(pcs_size, oopSize);
0N/A if ((nsize % sizeof(PcDesc)) != 0) {
0N/A nsize = pcs_size + sizeof(PcDesc);
0N/A }
2186N/A assert((nsize % oopSize) == 0, "correct alignment");
0N/A return nsize;
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A
0N/A
0N/Avoid nmethod::add_exception_cache_entry(ExceptionCache* new_entry) {
0N/A assert(ExceptionCache_lock->owned_by_self(),"Must hold the ExceptionCache_lock");
0N/A assert(new_entry != NULL,"Must be non null");
0N/A assert(new_entry->next() == NULL, "Must be null");
0N/A
0N/A if (exception_cache() != NULL) {
0N/A new_entry->set_next(exception_cache());
0N/A }
0N/A set_exception_cache(new_entry);
0N/A}
0N/A
0N/Avoid nmethod::remove_from_exception_cache(ExceptionCache* ec) {
0N/A ExceptionCache* prev = NULL;
0N/A ExceptionCache* curr = exception_cache();
0N/A assert(curr != NULL, "nothing to remove");
0N/A // find the previous and next entry of ec
0N/A while (curr != ec) {
0N/A prev = curr;
0N/A curr = curr->next();
0N/A assert(curr != NULL, "ExceptionCache not found");
0N/A }
0N/A // now: curr == ec
0N/A ExceptionCache* next = curr->next();
0N/A if (prev == NULL) {
0N/A set_exception_cache(next);
0N/A } else {
0N/A prev->set_next(next);
0N/A }
0N/A delete curr;
0N/A}
0N/A
0N/A
0N/A// public method for accessing the exception cache
0N/A// These are the public access methods.
0N/Aaddress nmethod::handler_for_exception_and_pc(Handle exception, address pc) {
0N/A // We never grab a lock to read the exception cache, so we may
0N/A // have false negatives. This is okay, as it can only happen during
0N/A // the first few exception lookups for a given nmethod.
0N/A ExceptionCache* ec = exception_cache();
0N/A while (ec != NULL) {
0N/A address ret_val;
0N/A if ((ret_val = ec->match(exception,pc)) != NULL) {
0N/A return ret_val;
0N/A }
0N/A ec = ec->next();
0N/A }
0N/A return NULL;
0N/A}
0N/A
0N/A
0N/Avoid nmethod::add_handler_for_exception_and_pc(Handle exception, address pc, address handler) {
0N/A // There are potential race conditions during exception cache updates, so we
0N/A // must own the ExceptionCache_lock before doing ANY modifications. Because
605N/A // we don't lock during reads, it is possible to have several threads attempt
0N/A // to update the cache with the same data. We need to check for already inserted
0N/A // copies of the current data before adding it.
0N/A
0N/A MutexLocker ml(ExceptionCache_lock);
0N/A ExceptionCache* target_entry = exception_cache_entry_for_exception(exception);
0N/A
0N/A if (target_entry == NULL || !target_entry->add_address_and_handler(pc,handler)) {
0N/A target_entry = new ExceptionCache(exception,pc,handler);
0N/A add_exception_cache_entry(target_entry);
0N/A }
0N/A}
0N/A
0N/A
0N/A//-------------end of code for ExceptionCache--------------
0N/A
0N/A
0N/Aint nmethod::total_size() const {
0N/A return
1682N/A consts_size() +
1668N/A insts_size() +
0N/A stub_size() +
0N/A scopes_data_size() +
0N/A scopes_pcs_size() +
0N/A handler_table_size() +
0N/A nul_chk_table_size();
0N/A}
0N/A
0N/Aconst char* nmethod::compile_kind() const {
0N/A if (is_osr_method()) return "osr";
1109N/A if (method() != NULL && is_native_method()) return "c2n";
0N/A return NULL;
0N/A}
0N/A
1564N/A// Fill in default values for various flag fields
1564N/Avoid nmethod::init_defaults() {
1564N/A _state = alive;
1564N/A _marked_for_reclamation = 0;
1564N/A _has_flushed_dependencies = 0;
1564N/A _speculatively_disconnected = 0;
1564N/A _has_unsafe_access = 0;
1564N/A _has_method_handle_invokes = 0;
3158N/A _lazy_critical_native = 0;
4012N/A _has_wide_vectors = 0;
1564N/A _marked_for_deoptimization = 0;
1564N/A _lock_count = 0;
1564N/A _stack_traversal_mark = 0;
1564N/A _unload_reported = false; // jvmti state
1564N/A
1646N/A#ifdef ASSERT
1646N/A _oops_are_stale = false;
1646N/A#endif
1646N/A
1564N/A _oops_do_mark_link = NULL;
1564N/A _jmethod_id = NULL;
1564N/A _osr_link = NULL;
1564N/A _scavenge_root_link = NULL;
1564N/A _scavenge_root_state = 0;
1564N/A _saved_nmethod_link = NULL;
1564N/A _compiler = NULL;
1564N/A
1564N/A#ifdef HAVE_DTRACE_H
1564N/A _trap_offset = 0;
1564N/A#endif // def HAVE_DTRACE_H
1564N/A}
0N/A
0N/A
0N/Anmethod* nmethod::new_native_nmethod(methodHandle method,
2252N/A int compile_id,
0N/A CodeBuffer *code_buffer,
0N/A int vep_offset,
0N/A int frame_complete,
0N/A int frame_size,
0N/A ByteSize basic_lock_owner_sp_offset,
0N/A ByteSize basic_lock_sp_offset,
0N/A OopMapSet* oop_maps) {
0N/A // create nmethod
0N/A nmethod* nm = NULL;
0N/A {
0N/A MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
0N/A int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
0N/A CodeOffsets offsets;
0N/A offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
0N/A offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
0N/A nm = new (native_nmethod_size)
2252N/A nmethod(method(), native_nmethod_size, compile_id, &offsets,
0N/A code_buffer, frame_size,
0N/A basic_lock_owner_sp_offset, basic_lock_sp_offset,
0N/A oop_maps);
0N/A NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_native_nmethod(nm));
0N/A if (PrintAssembly && nm != NULL)
0N/A Disassembler::decode(nm);
0N/A }
0N/A // verify nmethod
0N/A debug_only(if (nm) nm->verify();) // might block
0N/A
0N/A if (nm != NULL) {
0N/A nm->log_new_nmethod();
0N/A }
0N/A
0N/A return nm;
0N/A}
0N/A
116N/A#ifdef HAVE_DTRACE_H
116N/Anmethod* nmethod::new_dtrace_nmethod(methodHandle method,
116N/A CodeBuffer *code_buffer,
116N/A int vep_offset,
116N/A int trap_offset,
116N/A int frame_complete,
116N/A int frame_size) {
116N/A // create nmethod
116N/A nmethod* nm = NULL;
116N/A {
116N/A MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
116N/A int nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
116N/A CodeOffsets offsets;
116N/A offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
116N/A offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset);
116N/A offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
116N/A
116N/A nm = new (nmethod_size) nmethod(method(), nmethod_size, &offsets, code_buffer, frame_size);
116N/A
116N/A NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_nmethod(nm));
116N/A if (PrintAssembly && nm != NULL)
116N/A Disassembler::decode(nm);
116N/A }
116N/A // verify nmethod
116N/A debug_only(if (nm) nm->verify();) // might block
116N/A
116N/A if (nm != NULL) {
116N/A nm->log_new_nmethod();
116N/A }
116N/A
116N/A return nm;
116N/A}
116N/A
116N/A#endif // def HAVE_DTRACE_H
116N/A
0N/Anmethod* nmethod::new_nmethod(methodHandle method,
0N/A int compile_id,
0N/A int entry_bci,
0N/A CodeOffsets* offsets,
0N/A int orig_pc_offset,
0N/A DebugInformationRecorder* debug_info,
0N/A Dependencies* dependencies,
0N/A CodeBuffer* code_buffer, int frame_size,
0N/A OopMapSet* oop_maps,
0N/A ExceptionHandlerTable* handler_table,
0N/A ImplicitExceptionTable* nul_chk_table,
0N/A AbstractCompiler* compiler,
0N/A int comp_level
0N/A)
0N/A{
0N/A assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
0N/A // create nmethod
0N/A nmethod* nm = NULL;
0N/A { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
0N/A int nmethod_size =
0N/A allocation_size(code_buffer, sizeof(nmethod))
0N/A + adjust_pcs_size(debug_info->pcs_size())
0N/A + round_to(dependencies->size_in_bytes() , oopSize)
0N/A + round_to(handler_table->size_in_bytes(), oopSize)
0N/A + round_to(nul_chk_table->size_in_bytes(), oopSize)
0N/A + round_to(debug_info->data_size() , oopSize);
0N/A nm = new (nmethod_size)
0N/A nmethod(method(), nmethod_size, compile_id, entry_bci, offsets,
0N/A orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
0N/A oop_maps,
0N/A handler_table,
0N/A nul_chk_table,
0N/A compiler,
0N/A comp_level);
0N/A if (nm != NULL) {
0N/A // To make dependency checking during class loading fast, record
0N/A // the nmethod dependencies in the classes it is dependent on.
0N/A // This allows the dependency checking code to simply walk the
0N/A // class hierarchy above the loaded class, checking only nmethods
0N/A // which are dependent on those classes. The slow way is to
0N/A // check every nmethod for dependencies which makes it linear in
0N/A // the number of methods compiled. For applications with a lot
0N/A // classes the slow way is too slow.
0N/A for (Dependencies::DepStream deps(nm); deps.next(); ) {
0N/A klassOop klass = deps.context_type();
0N/A if (klass == NULL) continue; // ignore things like evol_method
0N/A
0N/A // record this nmethod as dependent on this klass
0N/A instanceKlass::cast(klass)->add_dependent_nmethod(nm);
0N/A }
0N/A }
0N/A NOT_PRODUCT(if (nm != NULL) nmethod_stats.note_nmethod(nm));
0N/A if (PrintAssembly && nm != NULL)
0N/A Disassembler::decode(nm);
0N/A }
0N/A
0N/A // verify nmethod
0N/A debug_only(if (nm) nm->verify();) // might block
0N/A
0N/A if (nm != NULL) {
0N/A nm->log_new_nmethod();
0N/A }
0N/A
0N/A // done
0N/A return nm;
0N/A}
0N/A
0N/A
0N/A// For native wrappers
0N/Anmethod::nmethod(
0N/A methodOop method,
0N/A int nmethod_size,
2252N/A int compile_id,
0N/A CodeOffsets* offsets,
0N/A CodeBuffer* code_buffer,
0N/A int frame_size,
0N/A ByteSize basic_lock_owner_sp_offset,
0N/A ByteSize basic_lock_sp_offset,
0N/A OopMapSet* oop_maps )
0N/A : CodeBlob("native nmethod", code_buffer, sizeof(nmethod),
0N/A nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps),
1926N/A _native_receiver_sp_offset(basic_lock_owner_sp_offset),
1926N/A _native_basic_lock_sp_offset(basic_lock_sp_offset)
0N/A{
0N/A {
0N/A debug_only(No_Safepoint_Verifier nsv;)
0N/A assert_locked_or_safepoint(CodeCache_lock);
0N/A
1564N/A init_defaults();
0N/A _method = method;
0N/A _entry_bci = InvocationEntryBci;
0N/A // We have no exception handler or deopt handler make the
0N/A // values something that will never match a pc like the nmethod vtable entry
0N/A _exception_offset = 0;
0N/A _deoptimize_offset = 0;
1204N/A _deoptimize_mh_offset = 0;
0N/A _orig_pc_offset = 0;
1564N/A
1668N/A _consts_offset = data_offset();
0N/A _stub_offset = data_offset();
1483N/A _oops_offset = data_offset();
1483N/A _scopes_data_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize);
0N/A _scopes_pcs_offset = _scopes_data_offset;
0N/A _dependencies_offset = _scopes_pcs_offset;
0N/A _handler_table_offset = _dependencies_offset;
0N/A _nul_chk_table_offset = _handler_table_offset;
0N/A _nmethod_end_offset = _nul_chk_table_offset;
2252N/A _compile_id = compile_id;
0N/A _comp_level = CompLevel_none;
1668N/A _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
1668N/A _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
0N/A _osr_entry_point = NULL;
0N/A _exception_cache = NULL;
0N/A _pc_desc_cache.reset_to(NULL);
0N/A
0N/A code_buffer->copy_oops_to(this);
2223N/A if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
2223N/A CodeCache::add_scavenge_root_nmethod(this);
2223N/A }
989N/A debug_only(verify_scavenge_root_oops());
0N/A CodeCache::commit(this);
0N/A }
0N/A
0N/A if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
0N/A ttyLocker ttyl; // keep the following output all in one block
0N/A // This output goes directly to the tty, not the compiler log.
0N/A // To enable tools to match it up with the compilation activity,
0N/A // be sure to tag this tty output with the compile ID.
0N/A if (xtty != NULL) {
0N/A xtty->begin_head("print_native_nmethod");
0N/A xtty->method(_method);
0N/A xtty->stamp();
0N/A xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
0N/A }
0N/A // print the header part first
0N/A print();
0N/A // then print the requested information
0N/A if (PrintNativeNMethods) {
0N/A print_code();
4010N/A if (oop_maps != NULL) {
4010N/A oop_maps->print();
4010N/A }
0N/A }
0N/A if (PrintRelocations) {
0N/A print_relocations();
0N/A }
0N/A if (xtty != NULL) {
0N/A xtty->tail("print_native_nmethod");
0N/A }
0N/A }
0N/A}
0N/A
116N/A// For dtrace wrappers
116N/A#ifdef HAVE_DTRACE_H
116N/Anmethod::nmethod(
116N/A methodOop method,
116N/A int nmethod_size,
116N/A CodeOffsets* offsets,
116N/A CodeBuffer* code_buffer,
116N/A int frame_size)
116N/A : CodeBlob("dtrace nmethod", code_buffer, sizeof(nmethod),
116N/A nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, NULL),
1926N/A _native_receiver_sp_offset(in_ByteSize(-1)),
1926N/A _native_basic_lock_sp_offset(in_ByteSize(-1))
116N/A{
116N/A {
116N/A debug_only(No_Safepoint_Verifier nsv;)
116N/A assert_locked_or_safepoint(CodeCache_lock);
116N/A
1564N/A init_defaults();
116N/A _method = method;
116N/A _entry_bci = InvocationEntryBci;
116N/A // We have no exception handler or deopt handler make the
116N/A // values something that will never match a pc like the nmethod vtable entry
116N/A _exception_offset = 0;
116N/A _deoptimize_offset = 0;
1204N/A _deoptimize_mh_offset = 0;
1378N/A _unwind_handler_offset = -1;
116N/A _trap_offset = offsets->value(CodeOffsets::Dtrace_trap);
116N/A _orig_pc_offset = 0;
1668N/A _consts_offset = data_offset();
116N/A _stub_offset = data_offset();
1483N/A _oops_offset = data_offset();
1483N/A _scopes_data_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize);
116N/A _scopes_pcs_offset = _scopes_data_offset;
116N/A _dependencies_offset = _scopes_pcs_offset;
116N/A _handler_table_offset = _dependencies_offset;
116N/A _nul_chk_table_offset = _handler_table_offset;
116N/A _nmethod_end_offset = _nul_chk_table_offset;
116N/A _compile_id = 0; // default
116N/A _comp_level = CompLevel_none;
1668N/A _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
1668N/A _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
116N/A _osr_entry_point = NULL;
116N/A _exception_cache = NULL;
116N/A _pc_desc_cache.reset_to(NULL);
116N/A
116N/A code_buffer->copy_oops_to(this);
989N/A debug_only(verify_scavenge_root_oops());
116N/A CodeCache::commit(this);
116N/A }
116N/A
116N/A if (PrintNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) {
116N/A ttyLocker ttyl; // keep the following output all in one block
116N/A // This output goes directly to the tty, not the compiler log.
116N/A // To enable tools to match it up with the compilation activity,
116N/A // be sure to tag this tty output with the compile ID.
116N/A if (xtty != NULL) {
116N/A xtty->begin_head("print_dtrace_nmethod");
116N/A xtty->method(_method);
116N/A xtty->stamp();
116N/A xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
116N/A }
116N/A // print the header part first
116N/A print();
116N/A // then print the requested information
116N/A if (PrintNMethods) {
116N/A print_code();
116N/A }
116N/A if (PrintRelocations) {
116N/A print_relocations();
116N/A }
116N/A if (xtty != NULL) {
116N/A xtty->tail("print_dtrace_nmethod");
116N/A }
116N/A }
116N/A}
116N/A#endif // def HAVE_DTRACE_H
0N/A
0N/Avoid* nmethod::operator new(size_t size, int nmethod_size) {
0N/A // Always leave some room in the CodeCache for I2C/C2I adapters
2200N/A if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL;
0N/A return CodeCache::allocate(nmethod_size);
0N/A}
0N/A
0N/A
0N/Anmethod::nmethod(
0N/A methodOop method,
0N/A int nmethod_size,
0N/A int compile_id,
0N/A int entry_bci,
0N/A CodeOffsets* offsets,
0N/A int orig_pc_offset,
0N/A DebugInformationRecorder* debug_info,
0N/A Dependencies* dependencies,
0N/A CodeBuffer *code_buffer,
0N/A int frame_size,
0N/A OopMapSet* oop_maps,
0N/A ExceptionHandlerTable* handler_table,
0N/A ImplicitExceptionTable* nul_chk_table,
0N/A AbstractCompiler* compiler,
0N/A int comp_level
0N/A )
0N/A : CodeBlob("nmethod", code_buffer, sizeof(nmethod),
0N/A nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps),
1926N/A _native_receiver_sp_offset(in_ByteSize(-1)),
1926N/A _native_basic_lock_sp_offset(in_ByteSize(-1))
0N/A{
0N/A assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
0N/A {
0N/A debug_only(No_Safepoint_Verifier nsv;)
0N/A assert_locked_or_safepoint(CodeCache_lock);
0N/A
1564N/A init_defaults();
0N/A _method = method;
1564N/A _entry_bci = entry_bci;
0N/A _compile_id = compile_id;
0N/A _comp_level = comp_level;
0N/A _compiler = compiler;
0N/A _orig_pc_offset = orig_pc_offset;
1668N/A
1668N/A // Section offsets
1682N/A _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts());
1682N/A _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs());
0N/A
0N/A // Exception handler and deopt handler are in the stub section
1971N/A assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set");
1971N/A assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set");
1668N/A _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions);
1668N/A _deoptimize_offset = _stub_offset + offsets->value(CodeOffsets::Deopt);
1971N/A if (offsets->value(CodeOffsets::DeoptMH) != -1) {
1682N/A _deoptimize_mh_offset = _stub_offset + offsets->value(CodeOffsets::DeoptMH);
1682N/A } else {
1682N/A _deoptimize_mh_offset = -1;
1682N/A }
1378N/A if (offsets->value(CodeOffsets::UnwindHandler) != -1) {
1668N/A _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler);
1378N/A } else {
1668N/A _unwind_handler_offset = -1;
1378N/A }
1668N/A
1483N/A _oops_offset = data_offset();
1483N/A _scopes_data_offset = _oops_offset + round_to(code_buffer->total_oop_size (), oopSize);
1483N/A _scopes_pcs_offset = _scopes_data_offset + round_to(debug_info->data_size (), oopSize);
0N/A _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size());
0N/A _handler_table_offset = _dependencies_offset + round_to(dependencies->size_in_bytes (), oopSize);
0N/A _nul_chk_table_offset = _handler_table_offset + round_to(handler_table->size_in_bytes(), oopSize);
0N/A _nmethod_end_offset = _nul_chk_table_offset + round_to(nul_chk_table->size_in_bytes(), oopSize);
0N/A
1668N/A _entry_point = code_begin() + offsets->value(CodeOffsets::Entry);
1668N/A _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry);
1668N/A _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry);
0N/A _exception_cache = NULL;
0N/A _pc_desc_cache.reset_to(scopes_pcs_begin());
0N/A
0N/A // Copy contents of ScopeDescRecorder to nmethod
0N/A code_buffer->copy_oops_to(this);
0N/A debug_info->copy_to(this);
0N/A dependencies->copy_to(this);
989N/A if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
989N/A CodeCache::add_scavenge_root_nmethod(this);
989N/A }
989N/A debug_only(verify_scavenge_root_oops());
0N/A
0N/A CodeCache::commit(this);
0N/A
0N/A // Copy contents of ExceptionHandlerTable to nmethod
0N/A handler_table->copy_to(this);
0N/A nul_chk_table->copy_to(this);
0N/A
0N/A // we use the information of entry points to find out if a method is
0N/A // static or non static
0N/A assert(compiler->is_c2() ||
0N/A _method->is_static() == (entry_point() == _verified_entry_point),
0N/A " entry points must be same for static methods and vice versa");
0N/A }
0N/A
100N/A bool printnmethods = PrintNMethods
100N/A || CompilerOracle::should_print(_method)
100N/A || CompilerOracle::has_option_string(_method, "PrintNMethods");
0N/A if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
0N/A print_nmethod(printnmethods);
0N/A }
0N/A}
0N/A
0N/A
0N/A// Print a short set of xml attributes to identify this nmethod. The
0N/A// output should be embedded in some other element.
0N/Avoid nmethod::log_identity(xmlStream* log) const {
0N/A log->print(" compile_id='%d'", compile_id());
0N/A const char* nm_kind = compile_kind();
0N/A if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind);
0N/A if (compiler() != NULL) {
0N/A log->print(" compiler='%s'", compiler()->name());
0N/A }
1703N/A if (TieredCompilation) {
1703N/A log->print(" level='%d'", comp_level());
1703N/A }
0N/A}
0N/A
0N/A
0N/A#define LOG_OFFSET(log, name) \
0N/A if ((intptr_t)name##_end() - (intptr_t)name##_begin()) \
0N/A log->print(" " XSTR(name) "_offset='%d'" , \
0N/A (intptr_t)name##_begin() - (intptr_t)this)
0N/A
0N/A
0N/Avoid nmethod::log_new_nmethod() const {
0N/A if (LogCompilation && xtty != NULL) {
0N/A ttyLocker ttyl;
0N/A HandleMark hm;
0N/A xtty->begin_elem("nmethod");
0N/A log_identity(xtty);
1668N/A xtty->print(" entry='" INTPTR_FORMAT "' size='%d'", code_begin(), size());
0N/A xtty->print(" address='" INTPTR_FORMAT "'", (intptr_t) this);
0N/A
0N/A LOG_OFFSET(xtty, relocation);
1682N/A LOG_OFFSET(xtty, consts);
1668N/A LOG_OFFSET(xtty, insts);
0N/A LOG_OFFSET(xtty, stub);
0N/A LOG_OFFSET(xtty, scopes_data);
0N/A LOG_OFFSET(xtty, scopes_pcs);
0N/A LOG_OFFSET(xtty, dependencies);
0N/A LOG_OFFSET(xtty, handler_table);
0N/A LOG_OFFSET(xtty, nul_chk_table);
0N/A LOG_OFFSET(xtty, oops);
0N/A
0N/A xtty->method(method());
0N/A xtty->stamp();
0N/A xtty->end_elem();
0N/A }
0N/A}
0N/A
0N/A#undef LOG_OFFSET
0N/A
0N/A
0N/A// Print out more verbose output usually for a newly created nmethod.
2252N/Avoid nmethod::print_on(outputStream* st, const char* msg) const {
0N/A if (st != NULL) {
0N/A ttyLocker ttyl;
3932N/A if (WizardMode) {
3932N/A CompileTask::print_compilation(st, this, msg, /*short_form:*/ true);
3932N/A st->print_cr(" (" INTPTR_FORMAT ")", this);
3932N/A } else {
3932N/A CompileTask::print_compilation(st, this, msg, /*short_form:*/ false);
3932N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid nmethod::print_nmethod(bool printmethod) {
0N/A ttyLocker ttyl; // keep the following output all in one block
0N/A if (xtty != NULL) {
0N/A xtty->begin_head("print_nmethod");
0N/A xtty->stamp();
0N/A xtty->end_head();
0N/A }
0N/A // print the header part first
0N/A print();
0N/A // then print the requested information
0N/A if (printmethod) {
0N/A print_code();
0N/A print_pcs();
3932N/A if (oop_maps()) {
3932N/A oop_maps()->print();
3932N/A }
0N/A }
0N/A if (PrintDebugInfo) {
0N/A print_scopes();
0N/A }
0N/A if (PrintRelocations) {
0N/A print_relocations();
0N/A }
0N/A if (PrintDependencies) {
0N/A print_dependencies();
0N/A }
0N/A if (PrintExceptionHandlers) {
0N/A print_handler_table();
0N/A print_nul_chk_table();
0N/A }
0N/A if (xtty != NULL) {
0N/A xtty->tail("print_nmethod");
0N/A }
0N/A}
0N/A
0N/A
1483N/A// Promote one word from an assembly-time handle to a live embedded oop.
1483N/Ainline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) {
1483N/A if (handle == NULL ||
1483N/A // As a special case, IC oops are initialized to 1 or -1.
1483N/A handle == (jobject) Universe::non_oop_word()) {
1483N/A (*dest) = (oop) handle;
1483N/A } else {
1483N/A (*dest) = JNIHandles::resolve_non_null(handle);
1483N/A }
1483N/A}
1483N/A
1483N/A
1483N/Avoid nmethod::copy_oops(GrowableArray<jobject>* array) {
1483N/A //assert(oops_size() == 0, "do this handshake just once, please");
1483N/A int length = array->length();
1483N/A assert((address)(oops_begin() + length) <= data_end(), "oops big enough");
1483N/A oop* dest = oops_begin();
1483N/A for (int index = 0 ; index < length; index++) {
1483N/A initialize_immediate_oop(&dest[index], array->at(index));
1483N/A }
1483N/A
1483N/A // Now we can fix up all the oops in the code. We need to do this
1483N/A // in the code because the assembler uses jobjects as placeholders.
1483N/A // The code and relocations have already been initialized by the
1483N/A // CodeBlob constructor, so it is valid even at this early point to
1483N/A // iterate over relocations and patch the code.
1483N/A fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true);
1483N/A}
1483N/A
1483N/A
1483N/Abool nmethod::is_at_poll_return(address pc) {
1483N/A RelocIterator iter(this, pc, pc+1);
1483N/A while (iter.next()) {
1483N/A if (iter.type() == relocInfo::poll_return_type)
1483N/A return true;
1483N/A }
1483N/A return false;
1483N/A}
1483N/A
1483N/A
1483N/Abool nmethod::is_at_poll_or_poll_return(address pc) {
1483N/A RelocIterator iter(this, pc, pc+1);
1483N/A while (iter.next()) {
1483N/A relocInfo::relocType t = iter.type();
1483N/A if (t == relocInfo::poll_return_type || t == relocInfo::poll_type)
1483N/A return true;
1483N/A }
1483N/A return false;
1483N/A}
1483N/A
1483N/A
1483N/Avoid nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) {
1483N/A // re-patch all oop-bearing instructions, just in case some oops moved
1483N/A RelocIterator iter(this, begin, end);
1483N/A while (iter.next()) {
1483N/A if (iter.type() == relocInfo::oop_type) {
1483N/A oop_Relocation* reloc = iter.oop_reloc();
1483N/A if (initialize_immediates && reloc->oop_is_immediate()) {
1483N/A oop* dest = reloc->oop_addr();
1483N/A initialize_immediate_oop(dest, (jobject) *dest);
1483N/A }
1483N/A // Refresh the oop-related bits of this instruction.
1483N/A reloc->fix_oop_relocation();
1483N/A }
1483N/A
1483N/A // There must not be any interfering patches or breakpoints.
1483N/A assert(!(iter.type() == relocInfo::breakpoint_type
1483N/A && iter.breakpoint_reloc()->active()),
1483N/A "no active breakpoint");
1483N/A }
1483N/A}
1483N/A
1483N/A
2222N/Avoid nmethod::verify_oop_relocations() {
2222N/A // Ensure sure that the code matches the current oop values
2222N/A RelocIterator iter(this, NULL, NULL);
2222N/A while (iter.next()) {
2222N/A if (iter.type() == relocInfo::oop_type) {
2222N/A oop_Relocation* reloc = iter.oop_reloc();
2222N/A if (!reloc->oop_is_immediate()) {
2222N/A reloc->verify_oop_relocation();
2222N/A }
2222N/A }
2222N/A }
2222N/A}
2222N/A
2222N/A
0N/AScopeDesc* nmethod::scope_desc_at(address pc) {
0N/A PcDesc* pd = pc_desc_at(pc);
0N/A guarantee(pd != NULL, "scope must be present");
0N/A return new ScopeDesc(this, pd->scope_decode_offset(),
1253N/A pd->obj_decode_offset(), pd->should_reexecute(),
1253N/A pd->return_oop());
0N/A}
0N/A
0N/A
0N/Avoid nmethod::clear_inline_caches() {
0N/A assert(SafepointSynchronize::is_at_safepoint(), "cleaning of IC's only allowed at safepoint");
0N/A if (is_zombie()) {
0N/A return;
0N/A }
0N/A
0N/A RelocIterator iter(this);
0N/A while (iter.next()) {
0N/A iter.reloc()->clear_inline_cache();
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid nmethod::cleanup_inline_caches() {
0N/A
1458N/A assert_locked_or_safepoint(CompiledIC_lock);
0N/A
0N/A // If the method is not entrant or zombie then a JMP is plastered over the
0N/A // first few bytes. If an oop in the old code was there, that oop
0N/A // should not get GC'd. Skip the first few bytes of oops on
0N/A // not-entrant methods.
0N/A address low_boundary = verified_entry_point();
0N/A if (!is_in_use()) {
0N/A low_boundary += NativeJump::instruction_size;
0N/A // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump.
0N/A // This means that the low_boundary is going to be a little too high.
0N/A // This shouldn't matter, since oops of non-entrant methods are never used.
0N/A // In fact, why are we bothering to look at oops in a non-entrant method??
0N/A }
0N/A
0N/A // Find all calls in an nmethod, and clear the ones that points to zombie methods
0N/A ResourceMark rm;
0N/A RelocIterator iter(this, low_boundary);
0N/A while(iter.next()) {
0N/A switch(iter.type()) {
0N/A case relocInfo::virtual_call_type:
0N/A case relocInfo::opt_virtual_call_type: {
0N/A CompiledIC *ic = CompiledIC_at(iter.reloc());
0N/A // Ok, to lookup references to zombies here
0N/A CodeBlob *cb = CodeCache::find_blob_unsafe(ic->ic_destination());
0N/A if( cb != NULL && cb->is_nmethod() ) {
0N/A nmethod* nm = (nmethod*)cb;
0N/A // Clean inline caches pointing to both zombie and not_entrant methods
1202N/A if (!nm->is_in_use() || (nm->method()->code() != nm)) ic->set_to_clean();
0N/A }
0N/A break;
0N/A }
0N/A case relocInfo::static_call_type: {
0N/A CompiledStaticCall *csc = compiledStaticCall_at(iter.reloc());
0N/A CodeBlob *cb = CodeCache::find_blob_unsafe(csc->destination());
0N/A if( cb != NULL && cb->is_nmethod() ) {
0N/A nmethod* nm = (nmethod*)cb;
0N/A // Clean inline caches pointing to both zombie and not_entrant methods
1202N/A if (!nm->is_in_use() || (nm->method()->code() != nm)) csc->set_to_clean();
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
989N/A// This is a private interface with the sweeper.
0N/Avoid nmethod::mark_as_seen_on_stack() {
0N/A assert(is_not_entrant(), "must be a non-entrant method");
1564N/A // Set the traversal mark to ensure that the sweeper does 2
1564N/A // cleaning passes before moving to zombie.
0N/A set_stack_traversal_mark(NMethodSweeper::traversal_count());
0N/A}
0N/A
2189N/A// Tell if a non-entrant method can be converted to a zombie (i.e.,
2189N/A// there are no activations on the stack, not in use by the VM,
2189N/A// and not in use by the ServiceThread)
0N/Abool nmethod::can_not_entrant_be_converted() {
0N/A assert(is_not_entrant(), "must be a non-entrant method");
0N/A
0N/A // Since the nmethod sweeper only does partial sweep the sweeper's traversal
0N/A // count can be greater than the stack traversal count before it hits the
0N/A // nmethod for the second time.
2189N/A return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() &&
2189N/A !is_locked_by_vm();
0N/A}
0N/A
0N/Avoid nmethod::inc_decompile_count() {
1703N/A if (!is_compiled_by_c2()) return;
0N/A // Could be gated by ProfileTraps, but do not bother...
0N/A methodOop m = method();
0N/A if (m == NULL) return;
0N/A methodDataOop mdo = m->method_data();
0N/A if (mdo == NULL) return;
0N/A // There is a benign race here. See comments in methodDataOop.hpp.
0N/A mdo->inc_decompile_count();
0N/A}
0N/A
0N/Avoid nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) {
0N/A
0N/A post_compiled_method_unload();
0N/A
0N/A // Since this nmethod is being unloaded, make sure that dependencies
0N/A // recorded in instanceKlasses get flushed and pass non-NULL closure to
0N/A // indicate that this work is being done during a GC.
0N/A assert(Universe::heap()->is_gc_active(), "should only be called during gc");
0N/A assert(is_alive != NULL, "Should be non-NULL");
0N/A // A non-NULL is_alive closure indicates that this is being called during GC.
0N/A flush_dependencies(is_alive);
0N/A
0N/A // Break cycle between nmethod & method
0N/A if (TraceClassUnloading && WizardMode) {
0N/A tty->print_cr("[Class unloading: Making nmethod " INTPTR_FORMAT
0N/A " unloadable], methodOop(" INTPTR_FORMAT
0N/A "), cause(" INTPTR_FORMAT ")",
0N/A this, (address)_method, (address)cause);
989N/A if (!Universe::heap()->is_gc_active())
989N/A cause->klass()->print();
0N/A }
941N/A // Unlink the osr method, so we do not look this up again
941N/A if (is_osr_method()) {
941N/A invalidate_osr_method();
941N/A }
0N/A // If _method is already NULL the methodOop is about to be unloaded,
0N/A // so we don't have to break the cycle. Note that it is possible to
0N/A // have the methodOop live here, in case we unload the nmethod because
0N/A // it is pointing to some oop (other than the methodOop) being unloaded.
0N/A if (_method != NULL) {
0N/A // OSR methods point to the methodOop, but the methodOop does not
0N/A // point back!
0N/A if (_method->code() == this) {
0N/A _method->clear_code(); // Break a cycle
0N/A }
0N/A _method = NULL; // Clear the method of this dead nmethod
0N/A }
0N/A // Make the class unloaded - i.e., change state and notify sweeper
1458N/A assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0N/A if (is_in_use()) {
0N/A // Transitioning directly from live to unloaded -- so
0N/A // we need to force a cache clean-up; remember this
0N/A // for later on.
0N/A CodeCache::set_needs_cache_clean(true);
0N/A }
1564N/A _state = unloaded;
0N/A
1109N/A // Log the unloading.
1109N/A log_state_change();
1109N/A
0N/A // The methodOop is gone at this point
0N/A assert(_method == NULL, "Tautology");
0N/A
989N/A set_osr_link(NULL);
989N/A //set_scavenge_root_link(NULL); // done by prune_scavenge_root_nmethods
0N/A NMethodSweeper::notify(this);
0N/A}
0N/A
0N/Avoid nmethod::invalidate_osr_method() {
0N/A assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod");
0N/A // Remove from list of active nmethods
0N/A if (method() != NULL)
0N/A instanceKlass::cast(method()->method_holder())->remove_osr_nmethod(this);
0N/A // Set entry as invalid
0N/A _entry_bci = InvalidOSREntryBci;
0N/A}
0N/A
1109N/Avoid nmethod::log_state_change() const {
0N/A if (LogCompilation) {
0N/A if (xtty != NULL) {
0N/A ttyLocker ttyl; // keep the following output all in one block
1564N/A if (_state == unloaded) {
1109N/A xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'",
1109N/A os::current_thread_id());
1109N/A } else {
1109N/A xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s",
1109N/A os::current_thread_id(),
1564N/A (_state == zombie ? " zombie='1'" : ""));
1109N/A }
0N/A log_identity(xtty);
0N/A xtty->stamp();
0N/A xtty->end_elem();
0N/A }
0N/A }
1564N/A if (PrintCompilation && _state != unloaded) {
2252N/A print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
0N/A }
0N/A}
0N/A
0N/A// Common functionality for both make_not_entrant and make_zombie
1141N/Abool nmethod::make_not_entrant_or_zombie(unsigned int state) {
0N/A assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
2189N/A assert(!is_zombie(), "should not already be a zombie");
0N/A
1564N/A // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
0N/A nmethodLocker nml(this);
1564N/A methodHandle the_method(method());
1646N/A No_Safepoint_Verifier nsv;
0N/A
0N/A {
1109N/A // invalidate osr nmethod before acquiring the patching lock since
1109N/A // they both acquire leaf locks and we don't want a deadlock.
1109N/A // This logic is equivalent to the logic below for patching the
1109N/A // verified entry point of regular methods.
1109N/A if (is_osr_method()) {
1109N/A // this effectively makes the osr nmethod not entrant
1109N/A invalidate_osr_method();
1109N/A }
1109N/A
0N/A // Enter critical section. Does not block for safepoint.
0N/A MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1109N/A
1564N/A if (_state == state) {
1109N/A // another thread already performed this transition so nothing
1109N/A // to do, but return false to indicate this.
1109N/A return false;
1109N/A }
1109N/A
0N/A // The caller can be calling the method statically or through an inline
0N/A // cache call.
1109N/A if (!is_osr_method() && !is_not_entrant()) {
0N/A NativeJump::patch_verified_entry(entry_point(), verified_entry_point(),
0N/A SharedRuntime::get_handle_wrong_method_stub());
0N/A }
0N/A
1564N/A if (is_in_use()) {
1564N/A // It's a true state change, so mark the method as decompiled.
1564N/A // Do it only for transition from alive.
1564N/A inc_decompile_count();
1564N/A }
1206N/A
0N/A // Change state
1564N/A _state = state;
1109N/A
1109N/A // Log the transition once
1109N/A log_state_change();
1109N/A
1564N/A // Remove nmethod from method.
1564N/A // We need to check if both the _code and _from_compiled_code_entry_point
1564N/A // refer to this nmethod because there is a race in setting these two fields
1564N/A // in methodOop as seen in bugid 4947125.
1564N/A // If the vep() points to the zombie nmethod, the memory for the nmethod
1564N/A // could be flushed and the compiler and vtable stubs could still call
1564N/A // through it.
1564N/A if (method() != NULL && (method()->code() == this ||
1564N/A method()->from_compiled_entry() == verified_entry_point())) {
1564N/A HandleMark hm;
1564N/A method()->clear_code();
1564N/A }
1564N/A
1564N/A if (state == not_entrant) {
1564N/A mark_as_seen_on_stack();
1564N/A }
1564N/A
0N/A } // leave critical region under Patching_lock
0N/A
1458N/A // When the nmethod becomes zombie it is no longer alive so the
1458N/A // dependencies must be flushed. nmethods in the not_entrant
1458N/A // state will be flushed later when the transition to zombie
1458N/A // happens or they get unloaded.
1458N/A if (state == zombie) {
1646N/A {
1646N/A // Flushing dependecies must be done before any possible
1646N/A // safepoint can sneak in, otherwise the oops used by the
1646N/A // dependency logic could have become stale.
1646N/A MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1646N/A flush_dependencies(NULL);
1646N/A }
1564N/A
2189N/A // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload
2189N/A // event and it hasn't already been reported for this nmethod then
2189N/A // report it now. The event may have been reported earilier if the GC
2189N/A // marked it for unloading). JvmtiDeferredEventQueue support means
2189N/A // we no longer go to a safepoint here.
2189N/A post_compiled_method_unload();
1646N/A
1646N/A#ifdef ASSERT
1646N/A // It's no longer safe to access the oops section since zombie
1646N/A // nmethods aren't scanned for GC.
1646N/A _oops_are_stale = true;
1646N/A#endif
1458N/A } else {
1458N/A assert(state == not_entrant, "other cases may need to be handled differently");
1458N/A }
1458N/A
0N/A if (TraceCreateZombies) {
0N/A tty->print_cr("nmethod <" INTPTR_FORMAT "> code made %s", this, (state == not_entrant) ? "not entrant" : "zombie");
0N/A }
0N/A
0N/A // Make sweeper aware that there is a zombie method that needs to be removed
0N/A NMethodSweeper::notify(this);
0N/A
1109N/A return true;
0N/A}
0N/A
0N/Avoid nmethod::flush() {
0N/A // Note that there are no valid oops in the nmethod anymore.
0N/A assert(is_zombie() || (is_osr_method() && is_unloaded()), "must be a zombie method");
0N/A assert(is_marked_for_reclamation() || (is_osr_method() && is_unloaded()), "must be marked for reclamation");
0N/A
0N/A assert (!is_locked_by_vm(), "locked methods shouldn't be flushed");
1458N/A assert_locked_or_safepoint(CodeCache_lock);
0N/A
0N/A // completely deallocate this method
3157N/A Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, this);
0N/A if (PrintMethodFlushing) {
1202N/A tty->print_cr("*flushing nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT "/Free CodeCache:" SIZE_FORMAT "Kb",
1202N/A _compile_id, this, CodeCache::nof_blobs(), CodeCache::unallocated_capacity()/1024);
0N/A }
0N/A
0N/A // We need to deallocate any ExceptionCache data.
0N/A // Note that we do not need to grab the nmethod lock for this, it
0N/A // better be thread safe if we're disposing of it!
0N/A ExceptionCache* ec = exception_cache();
0N/A set_exception_cache(NULL);
0N/A while(ec != NULL) {
0N/A ExceptionCache* next = ec->next();
0N/A delete ec;
0N/A ec = next;
0N/A }
0N/A
989N/A if (on_scavenge_root_list()) {
989N/A CodeCache::drop_scavenge_root_nmethod(this);
989N/A }
989N/A
1202N/A if (is_speculatively_disconnected()) {
1202N/A CodeCache::remove_saved_code(this);
1202N/A }
1202N/A
1612N/A#ifdef SHARK
1765N/A ((SharkCompiler *) compiler())->free_compiled_method(insts_begin());
1612N/A#endif // SHARK
1612N/A
0N/A ((CodeBlob*)(this))->flush();
0N/A
0N/A CodeCache::free(this);
0N/A}
0N/A
0N/A
0N/A//
0N/A// Notify all classes this nmethod is dependent on that it is no
0N/A// longer dependent. This should only be called in two situations.
0N/A// First, when a nmethod transitions to a zombie all dependents need
0N/A// to be clear. Since zombification happens at a safepoint there's no
0N/A// synchronization issues. The second place is a little more tricky.
0N/A// During phase 1 of mark sweep class unloading may happen and as a
0N/A// result some nmethods may get unloaded. In this case the flushing
0N/A// of dependencies must happen during phase 1 since after GC any
0N/A// dependencies in the unloaded nmethod won't be updated, so
0N/A// traversing the dependency information in unsafe. In that case this
0N/A// function is called with a non-NULL argument and this function only
0N/A// notifies instanceKlasses that are reachable
0N/A
0N/Avoid nmethod::flush_dependencies(BoolObjectClosure* is_alive) {
1458N/A assert_locked_or_safepoint(CodeCache_lock);
0N/A assert(Universe::heap()->is_gc_active() == (is_alive != NULL),
0N/A "is_alive is non-NULL if and only if we are called during GC");
0N/A if (!has_flushed_dependencies()) {
0N/A set_has_flushed_dependencies();
0N/A for (Dependencies::DepStream deps(this); deps.next(); ) {
0N/A klassOop klass = deps.context_type();
0N/A if (klass == NULL) continue; // ignore things like evol_method
0N/A
0N/A // During GC the is_alive closure is non-NULL, and is used to
0N/A // determine liveness of dependees that need to be updated.
0N/A if (is_alive == NULL || is_alive->do_object_b(klass)) {
0N/A instanceKlass::cast(klass)->remove_dependent_nmethod(this);
0N/A }
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/A// If this oop is not live, the nmethod can be unloaded.
0N/Abool nmethod::can_unload(BoolObjectClosure* is_alive,
0N/A OopClosure* keep_alive,
0N/A oop* root, bool unloading_occurred) {
0N/A assert(root != NULL, "just checking");
0N/A oop obj = *root;
0N/A if (obj == NULL || is_alive->do_object_b(obj)) {
0N/A return false;
0N/A }
0N/A if (obj->is_compiledICHolder()) {
0N/A compiledICHolderOop cichk_oop = compiledICHolderOop(obj);
0N/A if (is_alive->do_object_b(
0N/A cichk_oop->holder_method()->method_holder()) &&
0N/A is_alive->do_object_b(cichk_oop->holder_klass())) {
0N/A // The oop should be kept alive
0N/A keep_alive->do_oop(root);
0N/A return false;
0N/A }
0N/A }
989N/A // If ScavengeRootsInCode is true, an nmethod might be unloaded
989N/A // simply because one of its constant oops has gone dead.
989N/A // No actual classes need to be unloaded in order for this to occur.
989N/A assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading");
0N/A make_unloaded(is_alive, obj);
0N/A return true;
0N/A}
0N/A
0N/A// ------------------------------------------------------------------
0N/A// post_compiled_method_load_event
0N/A// new method for install_code() path
0N/A// Transfer information from compilation to jvmti
0N/Avoid nmethod::post_compiled_method_load_event() {
0N/A
0N/A methodOop moop = method();
2842N/A#ifndef USDT2
0N/A HS_DTRACE_PROBE8(hotspot, compiled__method__load,
0N/A moop->klass_name()->bytes(),
0N/A moop->klass_name()->utf8_length(),
0N/A moop->name()->bytes(),
0N/A moop->name()->utf8_length(),
0N/A moop->signature()->bytes(),
0N/A moop->signature()->utf8_length(),
1668N/A insts_begin(), insts_size());
2842N/A#else /* USDT2 */
2842N/A HOTSPOT_COMPILED_METHOD_LOAD(
2842N/A (char *) moop->klass_name()->bytes(),
2842N/A moop->klass_name()->utf8_length(),
2842N/A (char *) moop->name()->bytes(),
2842N/A moop->name()->utf8_length(),
2842N/A (char *) moop->signature()->bytes(),
2842N/A moop->signature()->utf8_length(),
2842N/A insts_begin(), insts_size());
2842N/A#endif /* USDT2 */
0N/A
1536N/A if (JvmtiExport::should_post_compiled_method_load() ||
1536N/A JvmtiExport::should_post_compiled_method_unload()) {
1536N/A get_and_cache_jmethod_id();
1536N/A }
1536N/A
0N/A if (JvmtiExport::should_post_compiled_method_load()) {
2076N/A // Let the Service thread (which is a real Java thread) post the event
2076N/A MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
2076N/A JvmtiDeferredEventQueue::enqueue(
2076N/A JvmtiDeferredEvent::compiled_method_load_event(this));
0N/A }
0N/A}
0N/A
1536N/AjmethodID nmethod::get_and_cache_jmethod_id() {
1536N/A if (_jmethod_id == NULL) {
1536N/A // Cache the jmethod_id since it can no longer be looked up once the
1536N/A // method itself has been marked for unloading.
1536N/A _jmethod_id = method()->jmethod_id();
1536N/A }
1536N/A return _jmethod_id;
1536N/A}
1536N/A
0N/Avoid nmethod::post_compiled_method_unload() {
1497N/A if (unload_reported()) {
1497N/A // During unloading we transition to unloaded and then to zombie
1497N/A // and the unloading is reported during the first transition.
1497N/A return;
1497N/A }
1497N/A
0N/A assert(_method != NULL && !is_unloaded(), "just checking");
0N/A DTRACE_METHOD_UNLOAD_PROBE(method());
0N/A
0N/A // If a JVMTI agent has enabled the CompiledMethodUnload event then
1536N/A // post the event. Sometime later this nmethod will be made a zombie
1536N/A // by the sweeper but the methodOop will not be valid at that point.
1536N/A // If the _jmethod_id is null then no load event was ever requested
1536N/A // so don't bother posting the unload. The main reason for this is
1536N/A // that the jmethodID is a weak reference to the methodOop so if
1536N/A // it's being unloaded there's no way to look it up since the weak
1536N/A // ref will have been cleared.
1536N/A if (_jmethod_id != NULL && JvmtiExport::should_post_compiled_method_unload()) {
0N/A assert(!unload_reported(), "already unloaded");
2076N/A JvmtiDeferredEvent event =
2189N/A JvmtiDeferredEvent::compiled_method_unload_event(this,
2076N/A _jmethod_id, insts_begin());
2076N/A if (SafepointSynchronize::is_at_safepoint()) {
2076N/A // Don't want to take the queueing lock. Add it as pending and
2076N/A // it will get enqueued later.
2076N/A JvmtiDeferredEventQueue::add_pending_event(event);
2076N/A } else {
2076N/A MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
2076N/A JvmtiDeferredEventQueue::enqueue(event);
2076N/A }
0N/A }
0N/A
0N/A // The JVMTI CompiledMethodUnload event can be enabled or disabled at
0N/A // any time. As the nmethod is being unloaded now we mark it has
0N/A // having the unload event reported - this will ensure that we don't
0N/A // attempt to report the event in the unlikely scenario where the
0N/A // event is enabled at the time the nmethod is made a zombie.
0N/A set_unload_reported();
0N/A}
0N/A
0N/A// This is called at the end of the strong tracing/marking phase of a
0N/A// GC to unload an nmethod if it contains otherwise unreachable
0N/A// oops.
0N/A
0N/Avoid nmethod::do_unloading(BoolObjectClosure* is_alive,
0N/A OopClosure* keep_alive, bool unloading_occurred) {
0N/A // Make sure the oop's ready to receive visitors
0N/A assert(!is_zombie() && !is_unloaded(),
0N/A "should not call follow on zombie or unloaded nmethod");
0N/A
0N/A // If the method is not entrant then a JMP is plastered over the
0N/A // first few bytes. If an oop in the old code was there, that oop
0N/A // should not get GC'd. Skip the first few bytes of oops on
0N/A // not-entrant methods.
0N/A address low_boundary = verified_entry_point();
0N/A if (is_not_entrant()) {
0N/A low_boundary += NativeJump::instruction_size;
0N/A // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump.
0N/A // (See comment above.)
0N/A }
0N/A
0N/A // The RedefineClasses() API can cause the class unloading invariant
0N/A // to no longer be true. See jvmtiExport.hpp for details.
0N/A // Also, leave a debugging breadcrumb in local flag.
0N/A bool a_class_was_redefined = JvmtiExport::has_redefined_a_class();
0N/A if (a_class_was_redefined) {
0N/A // This set of the unloading_occurred flag is done before the
0N/A // call to post_compiled_method_unload() so that the unloading
0N/A // of this nmethod is reported.
0N/A unloading_occurred = true;
0N/A }
0N/A
0N/A // Follow methodOop
0N/A if (can_unload(is_alive, keep_alive, (oop*)&_method, unloading_occurred)) {
0N/A return;
0N/A }
0N/A
0N/A // Exception cache
0N/A ExceptionCache* ec = exception_cache();
0N/A while (ec != NULL) {
0N/A oop* ex_addr = (oop*)ec->exception_type_addr();
0N/A oop ex = *ex_addr;
0N/A ExceptionCache* next_ec = ec->next();
0N/A if (ex != NULL && !is_alive->do_object_b(ex)) {
0N/A assert(!ex->is_compiledICHolder(), "Possible error here");
0N/A remove_from_exception_cache(ec);
0N/A }
0N/A ec = next_ec;
0N/A }
0N/A
0N/A // If class unloading occurred we first iterate over all inline caches and
0N/A // clear ICs where the cached oop is referring to an unloaded klass or method.
0N/A // The remaining live cached oops will be traversed in the relocInfo::oop_type
0N/A // iteration below.
0N/A if (unloading_occurred) {
0N/A RelocIterator iter(this, low_boundary);
0N/A while(iter.next()) {
0N/A if (iter.type() == relocInfo::virtual_call_type) {
0N/A CompiledIC *ic = CompiledIC_at(iter.reloc());
0N/A oop ic_oop = ic->cached_oop();
0N/A if (ic_oop != NULL && !is_alive->do_object_b(ic_oop)) {
0N/A // The only exception is compiledICHolder oops which may
0N/A // yet be marked below. (We check this further below).
0N/A if (ic_oop->is_compiledICHolder()) {
0N/A compiledICHolderOop cichk_oop = compiledICHolderOop(ic_oop);
0N/A if (is_alive->do_object_b(
0N/A cichk_oop->holder_method()->method_holder()) &&
0N/A is_alive->do_object_b(cichk_oop->holder_klass())) {
0N/A continue;
0N/A }
0N/A }
0N/A ic->set_to_clean();
1409N/A assert(ic->cached_oop() == NULL,
1409N/A "cached oop in IC should be cleared");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Compiled code
0N/A RelocIterator iter(this, low_boundary);
0N/A while (iter.next()) {
0N/A if (iter.type() == relocInfo::oop_type) {
0N/A oop_Relocation* r = iter.oop_reloc();
0N/A // In this loop, we must only traverse those oops directly embedded in
0N/A // the code. Other oops (oop_index>0) are seen as part of scopes_oops.
0N/A assert(1 == (r->oop_is_immediate()) +
0N/A (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()),
0N/A "oop must be found in exactly one place");
0N/A if (r->oop_is_immediate() && r->oop_value() != NULL) {
0N/A if (can_unload(is_alive, keep_alive, r->oop_addr(), unloading_occurred)) {
0N/A return;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A // Scopes
0N/A for (oop* p = oops_begin(); p < oops_end(); p++) {
0N/A if (*p == Universe::non_oop_word()) continue; // skip non-oops
0N/A if (can_unload(is_alive, keep_alive, p, unloading_occurred)) {
0N/A return;
0N/A }
0N/A }
0N/A
0N/A#ifndef PRODUCT
0N/A // This nmethod was not unloaded; check below that all CompiledICs
0N/A // refer to marked oops.
0N/A {
0N/A RelocIterator iter(this, low_boundary);
0N/A while (iter.next()) {
0N/A if (iter.type() == relocInfo::virtual_call_type) {
0N/A CompiledIC *ic = CompiledIC_at(iter.reloc());
0N/A oop ic_oop = ic->cached_oop();
0N/A assert(ic_oop == NULL || is_alive->do_object_b(ic_oop),
0N/A "Found unmarked ic_oop in reachable nmethod");
0N/A }
0N/A }
0N/A }
0N/A#endif // !PRODUCT
0N/A}
0N/A
941N/A// This method is called twice during GC -- once while
941N/A// tracing the "active" nmethods on thread stacks during
941N/A// the (strong) marking phase, and then again when walking
941N/A// the code cache contents during the weak roots processing
941N/A// phase. The two uses are distinguished by means of the
994N/A// 'do_strong_roots_only' flag, which is true in the first
941N/A// case. We want to walk the weak roots in the nmethod
941N/A// only in the second case. The weak roots in the nmethod
941N/A// are the oops in the ExceptionCache and the InlineCache
941N/A// oops.
994N/Avoid nmethod::oops_do(OopClosure* f, bool do_strong_roots_only) {
0N/A // make sure the oops ready to receive visitors
0N/A assert(!is_zombie() && !is_unloaded(),
0N/A "should not call follow on zombie or unloaded nmethod");
0N/A
0N/A // If the method is not entrant or zombie then a JMP is plastered over the
0N/A // first few bytes. If an oop in the old code was there, that oop
0N/A // should not get GC'd. Skip the first few bytes of oops on
0N/A // not-entrant methods.
0N/A address low_boundary = verified_entry_point();
0N/A if (is_not_entrant()) {
0N/A low_boundary += NativeJump::instruction_size;
0N/A // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump.
0N/A // (See comment above.)
0N/A }
0N/A
0N/A // Compiled code
0N/A f->do_oop((oop*) &_method);
994N/A if (!do_strong_roots_only) {
941N/A // weak roots processing phase -- update ExceptionCache oops
941N/A ExceptionCache* ec = exception_cache();
941N/A while(ec != NULL) {
941N/A f->do_oop((oop*)ec->exception_type_addr());
941N/A ec = ec->next();
941N/A }
941N/A } // Else strong roots phase -- skip oops in ExceptionCache
0N/A
0N/A RelocIterator iter(this, low_boundary);
941N/A
0N/A while (iter.next()) {
0N/A if (iter.type() == relocInfo::oop_type ) {
0N/A oop_Relocation* r = iter.oop_reloc();
0N/A // In this loop, we must only follow those oops directly embedded in
0N/A // the code. Other oops (oop_index>0) are seen as part of scopes_oops.
941N/A assert(1 == (r->oop_is_immediate()) +
941N/A (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()),
941N/A "oop must be found in exactly one place");
0N/A if (r->oop_is_immediate() && r->oop_value() != NULL) {
0N/A f->do_oop(r->oop_addr());
0N/A }
0N/A }
0N/A }
0N/A
0N/A // Scopes
989N/A // This includes oop constants not inlined in the code stream.
0N/A for (oop* p = oops_begin(); p < oops_end(); p++) {
0N/A if (*p == Universe::non_oop_word()) continue; // skip non-oops
0N/A f->do_oop(p);
0N/A }
0N/A}
0N/A
989N/A#define NMETHOD_SENTINEL ((nmethod*)badAddress)
989N/A
989N/Anmethod* volatile nmethod::_oops_do_mark_nmethods;
989N/A
989N/A// An nmethod is "marked" if its _mark_link is set non-null.
989N/A// Even if it is the end of the linked list, it will have a non-null link value,
989N/A// as long as it is on the list.
989N/A// This code must be MP safe, because it is used from parallel GC passes.
989N/Abool nmethod::test_set_oops_do_mark() {
989N/A assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called");
989N/A nmethod* observed_mark_link = _oops_do_mark_link;
989N/A if (observed_mark_link == NULL) {
989N/A // Claim this nmethod for this thread to mark.
989N/A observed_mark_link = (nmethod*)
989N/A Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL);
989N/A if (observed_mark_link == NULL) {
989N/A
989N/A // Atomically append this nmethod (now claimed) to the head of the list:
989N/A nmethod* observed_mark_nmethods = _oops_do_mark_nmethods;
989N/A for (;;) {
989N/A nmethod* required_mark_nmethods = observed_mark_nmethods;
989N/A _oops_do_mark_link = required_mark_nmethods;
989N/A observed_mark_nmethods = (nmethod*)
989N/A Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods);
989N/A if (observed_mark_nmethods == required_mark_nmethods)
989N/A break;
989N/A }
989N/A // Mark was clear when we first saw this guy.
2252N/A NOT_PRODUCT(if (TraceScavenge) print_on(tty, "oops_do, mark"));
989N/A return false;
989N/A }
989N/A }
989N/A // On fall through, another racing thread marked this nmethod before we did.
989N/A return true;
989N/A}
989N/A
989N/Avoid nmethod::oops_do_marking_prologue() {
989N/A NOT_PRODUCT(if (TraceScavenge) tty->print_cr("[oops_do_marking_prologue"));
989N/A assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row");
989N/A // We use cmpxchg_ptr instead of regular assignment here because the user
989N/A // may fork a bunch of threads, and we need them all to see the same state.
989N/A void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL);
989N/A guarantee(observed == NULL, "no races in this sequential code");
989N/A}
989N/A
989N/Avoid nmethod::oops_do_marking_epilogue() {
989N/A assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row");
989N/A nmethod* cur = _oops_do_mark_nmethods;
989N/A while (cur != NMETHOD_SENTINEL) {
989N/A assert(cur != NULL, "not NULL-terminated");
989N/A nmethod* next = cur->_oops_do_mark_link;
989N/A cur->_oops_do_mark_link = NULL;
2222N/A cur->fix_oop_relocations();
2252N/A NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark"));
989N/A cur = next;
989N/A }
989N/A void* required = _oops_do_mark_nmethods;
989N/A void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required);
989N/A guarantee(observed == required, "no races in this sequential code");
989N/A NOT_PRODUCT(if (TraceScavenge) tty->print_cr("oops_do_marking_epilogue]"));
989N/A}
989N/A
989N/Aclass DetectScavengeRoot: public OopClosure {
989N/A bool _detected_scavenge_root;
989N/Apublic:
989N/A DetectScavengeRoot() : _detected_scavenge_root(false)
989N/A { NOT_PRODUCT(_print_nm = NULL); }
989N/A bool detected_scavenge_root() { return _detected_scavenge_root; }
989N/A virtual void do_oop(oop* p) {
989N/A if ((*p) != NULL && (*p)->is_scavengable()) {
989N/A NOT_PRODUCT(maybe_print(p));
989N/A _detected_scavenge_root = true;
989N/A }
989N/A }
989N/A virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
989N/A
989N/A#ifndef PRODUCT
989N/A nmethod* _print_nm;
989N/A void maybe_print(oop* p) {
989N/A if (_print_nm == NULL) return;
989N/A if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root");
2474N/A tty->print_cr(""PTR_FORMAT"[offset=%d] detected scavengable oop "PTR_FORMAT" (found at "PTR_FORMAT")",
989N/A _print_nm, (int)((intptr_t)p - (intptr_t)_print_nm),
989N/A (intptr_t)(*p), (intptr_t)p);
989N/A (*p)->print();
989N/A }
989N/A#endif //PRODUCT
989N/A};
989N/A
989N/Abool nmethod::detect_scavenge_root_oops() {
989N/A DetectScavengeRoot detect_scavenge_root;
989N/A NOT_PRODUCT(if (TraceScavenge) detect_scavenge_root._print_nm = this);
989N/A oops_do(&detect_scavenge_root);
989N/A return detect_scavenge_root.detected_scavenge_root();
989N/A}
Error!

 

There was an error!

null

java.lang.NullPointerException