Path: blob/master/src/hotspot/share/code/dependencyContext.hpp
40931 views
/*1* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CODE_DEPENDENCYCONTEXT_HPP25#define SHARE_CODE_DEPENDENCYCONTEXT_HPP2627#include "memory/allocation.hpp"28#include "oops/oop.hpp"29#include "runtime/handles.hpp"30#include "runtime/perfData.hpp"31#include "runtime/safepoint.hpp"3233class nmethod;34class DepChange;3536//37// nmethodBucket is used to record dependent nmethods for38// deoptimization. nmethod dependencies are actually <klass, method>39// pairs but we really only care about the klass part for purposes of40// finding nmethods which might need to be deoptimized. Instead of41// recording the method, a count of how many times a particular nmethod42// was recorded is kept. This ensures that any recording errors are43// noticed since an nmethod should be removed as many times are it's44// added.45//46class nmethodBucket: public CHeapObj<mtClass> {47friend class VMStructs;48private:49nmethod* _nmethod;50volatile int _count;51nmethodBucket* volatile _next;52nmethodBucket* volatile _purge_list_next;5354public:55nmethodBucket(nmethod* nmethod, nmethodBucket* next) :56_nmethod(nmethod), _count(1), _next(next), _purge_list_next(NULL) {}5758int count() { return _count; }59int increment() { _count += 1; return _count; }60int decrement();61nmethodBucket* next();62nmethodBucket* next_not_unloading();63void set_next(nmethodBucket* b);64nmethodBucket* purge_list_next();65void set_purge_list_next(nmethodBucket* b);66nmethod* get_nmethod() { return _nmethod; }67};6869//70// Utility class to manipulate nmethod dependency context.71// Dependency context can be attached either to an InstanceKlass (_dep_context field)72// or CallSiteContext oop for call_site_target dependencies (see javaClasses.hpp).73// DependencyContext class operates on some location which holds a nmethodBucket* value74// and uint64_t integer recording the safepoint counter at the last cleanup.75//76class DependencyContext : public StackObj {77friend class VMStructs;78friend class TestDependencyContext;79private:80nmethodBucket* volatile* _dependency_context_addr;81volatile uint64_t* _last_cleanup_addr;8283bool claim_cleanup();84void set_dependencies(nmethodBucket* b);85nmethodBucket* dependencies();86nmethodBucket* dependencies_not_unloading();8788static PerfCounter* _perf_total_buckets_allocated_count;89static PerfCounter* _perf_total_buckets_deallocated_count;90static PerfCounter* _perf_total_buckets_stale_count;91static PerfCounter* _perf_total_buckets_stale_acc_count;92static nmethodBucket* volatile _purge_list;93static uint64_t _cleaning_epoch_monotonic;94static volatile uint64_t _cleaning_epoch;9596public:97#ifdef ASSERT98// Safepoints are forbidden during DC lifetime. GC can invalidate99// _dependency_context_addr if it relocates the holder100// (e.g. CallSiteContext Java object).101SafepointStateTracker _safepoint_tracker;102103DependencyContext(nmethodBucket* volatile* bucket_addr, volatile uint64_t* last_cleanup_addr)104: _dependency_context_addr(bucket_addr),105_last_cleanup_addr(last_cleanup_addr),106_safepoint_tracker(SafepointSynchronize::safepoint_state_tracker()) {}107108~DependencyContext() {109assert(!_safepoint_tracker.safepoint_state_changed(), "must be the same safepoint");110}111#else112DependencyContext(nmethodBucket* volatile* bucket_addr, volatile uint64_t* last_cleanup_addr)113: _dependency_context_addr(bucket_addr),114_last_cleanup_addr(last_cleanup_addr) {}115#endif // ASSERT116117static void init();118119int mark_dependent_nmethods(DepChange& changes);120void add_dependent_nmethod(nmethod* nm);121void remove_dependent_nmethod(nmethod* nm);122int remove_all_dependents();123void clean_unloading_dependents();124static void purge_dependency_contexts();125static void release(nmethodBucket* b);126static void cleaning_start();127static void cleaning_end();128129#ifndef PRODUCT130void print_dependent_nmethods(bool verbose);131#endif //PRODUCT132bool is_dependent_nmethod(nmethod* nm);133};134#endif // SHARE_CODE_DEPENDENCYCONTEXT_HPP135136137