Path: blob/master/src/hotspot/share/interpreter/oopMapCache.hpp
40949 views
/*1* Copyright (c) 1997, 2019, 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_INTERPRETER_OOPMAPCACHE_HPP25#define SHARE_INTERPRETER_OOPMAPCACHE_HPP2627#include "oops/generateOopMap.hpp"28#include "runtime/mutex.hpp"2930// A Cache for storing (method, bci) -> oopMap.31// The memory management system uses the cache when locating object32// references in an interpreted frame.33//34// OopMapCache's are allocated lazily per InstanceKlass.3536// The oopMap (InterpreterOopMap) is stored as a bit mask. If the37// bit_mask can fit into two words it is stored in38// the _bit_mask array, otherwise it is allocated on the heap.39// For OopMapCacheEntry the bit_mask is allocated in the C heap40// because these entries persist between garbage collections.41// For InterpreterOopMap the bit_mask is allocated in42// a resource area for better performance. InterpreterOopMap43// should only be created and deleted during same garbage collection.44//45// If ENABBLE_ZAP_DEAD_LOCALS is defined, two bits are used46// per entry instead of one. In all cases,47// the first bit is set to indicate oops as opposed to other48// values. If the second bit is available,49// it is set for dead values. We get the following encoding:50//51// 00 live value52// 01 live oop53// 10 dead value54// 11 <unused> (we cannot distinguish between dead oops or values with the current oop map generator)555657class OffsetClosure {58public:59virtual void offset_do(int offset) = 0;60};6162class OopMapCacheEntry;6364class InterpreterOopMap: ResourceObj {65friend class OopMapCache;6667public:68enum {69N = 4, // the number of words reserved70// for inlined mask storage71small_mask_limit = N * BitsPerWord, // the maximum number of bits72// available for small masks,73// small_mask_limit can be set to 074// for testing bit_mask allocation7576bits_per_entry = 2,77dead_bit_number = 1,78oop_bit_number = 079};8081private:82Method* _method; // the method for which the mask is valid83unsigned short _bci; // the bci for which the mask is valid84int _mask_size; // the mask size in bits85int _expression_stack_size; // the size of the expression stack in slots8687protected:88intptr_t _bit_mask[N]; // the bit mask if89// mask_size <= small_mask_limit,90// ptr to bit mask otherwise91// "protected" so that sub classes can92// access it without using trickery in93// methd bit_mask().94#ifdef ASSERT95bool _resource_allocate_bit_mask;96#endif9798// access methods99Method* method() const { return _method; }100void set_method(Method* v) { _method = v; }101int bci() const { return _bci; }102void set_bci(int v) { _bci = v; }103int mask_size() const { return _mask_size; }104void set_mask_size(int v) { _mask_size = v; }105// Test bit mask size and return either the in-line bit mask or allocated106// bit mask.107uintptr_t* bit_mask() const { return (uintptr_t*)(mask_size() <= small_mask_limit ? (intptr_t)_bit_mask : _bit_mask[0]); }108109// return the word size of_bit_mask. mask_size() <= 4 * MAX_USHORT110size_t mask_word_size() const {111return (mask_size() + BitsPerWord - 1) / BitsPerWord;112}113114uintptr_t entry_at(int offset) const { int i = offset * bits_per_entry; return bit_mask()[i / BitsPerWord] >> (i % BitsPerWord); }115116void set_expression_stack_size(int sz) { _expression_stack_size = sz; }117118// Lookup119bool match(const methodHandle& method, int bci) const { return _method == method() && _bci == bci; }120bool is_empty() const;121122// Initialization123void initialize();124125public:126InterpreterOopMap();127~InterpreterOopMap();128129// Copy the OopMapCacheEntry in parameter "from" into this130// InterpreterOopMap. If the _bit_mask[0] in "from" points to131// allocated space (i.e., the bit mask was to large to hold132// in-line), allocate the space from a Resource area.133void resource_copy(OopMapCacheEntry* from);134135void iterate_oop(OffsetClosure* oop_closure) const;136void print() const;137138int number_of_entries() const { return mask_size() / bits_per_entry; }139bool is_dead(int offset) const { return (entry_at(offset) & (1 << dead_bit_number)) != 0; }140bool is_oop (int offset) const { return (entry_at(offset) & (1 << oop_bit_number )) != 0; }141142int expression_stack_size() const { return _expression_stack_size; }143144};145146class OopMapCache : public CHeapObj<mtClass> {147static OopMapCacheEntry* volatile _old_entries;148private:149enum { _size = 32, // Use fixed size for now150_probe_depth = 3 // probe depth in case of collisions151};152153OopMapCacheEntry* volatile * _array;154155unsigned int hash_value_for(const methodHandle& method, int bci) const;156OopMapCacheEntry* entry_at(int i) const;157bool put_at(int i, OopMapCacheEntry* entry, OopMapCacheEntry* old);158159static void enqueue_for_cleanup(OopMapCacheEntry* entry);160161void flush();162163public:164OopMapCache();165~OopMapCache(); // free up memory166167// flush cache entry is occupied by an obsolete method168void flush_obsolete_entries();169170// Returns the oopMap for (method, bci) in parameter "entry".171// Returns false if an oop map was not found.172void lookup(const methodHandle& method, int bci, InterpreterOopMap* entry);173174// Compute an oop map without updating the cache or grabbing any locks (for debugging)175static void compute_one_oop_map(const methodHandle& method, int bci, InterpreterOopMap* entry);176static void cleanup_old_entries();177};178179#endif // SHARE_INTERPRETER_OOPMAPCACHE_HPP180181182