Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/compiler/oopMap.hpp
48773 views
/*1* Copyright (c) 1998, 2010, 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_VM_COMPILER_OOPMAP_HPP25#define SHARE_VM_COMPILER_OOPMAP_HPP2627#include "code/compressedStream.hpp"28#include "code/vmreg.hpp"29#include "memory/allocation.hpp"30#include "utilities/growableArray.hpp"3132// Interface for generating the frame map for compiled code. A frame map33// describes for a specific pc whether each register and frame stack slot is:34// Oop - A GC root for current frame35// Value - Live non-oop, non-float value: int, either half of double36// Dead - Dead; can be Zapped for debugging37// CalleeXX - Callee saved; also describes which caller register is saved38// DerivedXX - A derived oop; original oop is described.39//40// OopMapValue describes a single OopMap entry4142class frame;43class RegisterMap;44class DerivedPointerEntry;4546class OopMapValue: public StackObj {47friend class VMStructs;48private:49short _value;50int value() const { return _value; }51void set_value(int value) { _value = value; }52short _content_reg;5354public:55// Constants56enum { type_bits = 5,57register_bits = BitsPerShort - type_bits };5859enum { type_shift = 0,60register_shift = type_bits };6162enum { type_mask = right_n_bits(type_bits),63type_mask_in_place = type_mask << type_shift,64register_mask = right_n_bits(register_bits),65register_mask_in_place = register_mask << register_shift };6667enum oop_types { // must fit in type_bits68unused_value =0, // powers of 2, for masking OopMapStream69oop_value = 1,70value_value = 2,71narrowoop_value = 4,72callee_saved_value = 8,73derived_oop_value= 16 };7475// Constructors76OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }77OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg, t); set_content_reg(VMRegImpl::Bad()); }78OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg, t); set_content_reg(reg2); }79OopMapValue (CompressedReadStream* stream) { read_from(stream); }8081// Archiving82void write_on(CompressedWriteStream* stream) {83stream->write_int(value());84if(is_callee_saved() || is_derived_oop()) {85stream->write_int(content_reg()->value());86}87}8889void read_from(CompressedReadStream* stream) {90set_value(stream->read_int());91if (is_callee_saved() || is_derived_oop()) {92set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));93}94}9596// Querying97bool is_oop() { return mask_bits(value(), type_mask_in_place) == oop_value; }98bool is_value() { return mask_bits(value(), type_mask_in_place) == value_value; }99bool is_narrowoop() { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }100bool is_callee_saved() { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }101bool is_derived_oop() { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }102103void set_oop() { set_value((value() & register_mask_in_place) | oop_value); }104void set_value() { set_value((value() & register_mask_in_place) | value_value); }105void set_narrowoop() { set_value((value() & register_mask_in_place) | narrowoop_value); }106void set_callee_saved() { set_value((value() & register_mask_in_place) | callee_saved_value); }107void set_derived_oop() { set_value((value() & register_mask_in_place) | derived_oop_value); }108109VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }110oop_types type() const { return (oop_types)mask_bits(value(), type_mask_in_place); }111112static bool legal_vm_reg_name(VMReg p) {113return (p->value() == (p->value() & register_mask));114}115116void set_reg_type(VMReg p, oop_types t) {117set_value((p->value() << register_shift) | t);118assert(reg() == p, "sanity check" );119assert(type() == t, "sanity check" );120}121122123VMReg content_reg() const { return VMRegImpl::as_VMReg(_content_reg, true); }124void set_content_reg(VMReg r) { _content_reg = r->value(); }125126// Physical location queries127bool is_register_loc() { return reg()->is_reg(); }128bool is_stack_loc() { return reg()->is_stack(); }129130// Returns offset from sp.131int stack_offset() {132assert(is_stack_loc(), "must be stack location");133return reg()->reg2stack();134}135136void print_on(outputStream* st) const;137void print() const { print_on(tty); }138};139140141class OopMap: public ResourceObj {142friend class OopMapStream;143friend class VMStructs;144private:145int _pc_offset;146int _omv_count;147int _omv_data_size;148unsigned char* _omv_data;149CompressedWriteStream* _write_stream;150151debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)152153// Accessors154unsigned char* omv_data() const { return _omv_data; }155void set_omv_data(unsigned char* value) { _omv_data = value; }156int omv_data_size() const { return _omv_data_size; }157void set_omv_data_size(int value) { _omv_data_size = value; }158int omv_count() const { return _omv_count; }159void set_omv_count(int value) { _omv_count = value; }160void increment_count() { _omv_count++; }161CompressedWriteStream* write_stream() const { return _write_stream; }162void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }163164private:165enum DeepCopyToken { _deep_copy_token };166OopMap(DeepCopyToken, OopMap* source); // used only by deep_copy167168public:169OopMap(int frame_size, int arg_count);170171// pc-offset handling172int offset() const { return _pc_offset; }173void set_offset(int o) { _pc_offset = o; }174175// Check to avoid double insertion176debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })177178// Construction179// frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd180// slots to hold 4-byte values like ints and floats in the LP64 build.181void set_oop ( VMReg local);182void set_value( VMReg local);183void set_narrowoop(VMReg local);184void set_dead ( VMReg local);185void set_callee_saved( VMReg local, VMReg caller_machine_register );186void set_derived_oop ( VMReg local, VMReg derived_from_local_register );187void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);188189int heap_size() const;190void copy_to(address addr);191OopMap* deep_copy();192193bool has_derived_pointer() const PRODUCT_RETURN0;194195bool legal_vm_reg_name(VMReg local) {196return OopMapValue::legal_vm_reg_name(local);197}198199// Printing200void print_on(outputStream* st) const;201void print() const { print_on(tty); }202};203204205class OopMapSet : public ResourceObj {206friend class VMStructs;207private:208int _om_count;209int _om_size;210OopMap** _om_data;211212int om_count() const { return _om_count; }213void set_om_count(int value) { _om_count = value; }214void increment_count() { _om_count++; }215int om_size() const { return _om_size; }216void set_om_size(int value) { _om_size = value; }217OopMap** om_data() const { return _om_data; }218void set_om_data(OopMap** value) { _om_data = value; }219void grow_om_data();220void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }221222public:223OopMapSet();224225// returns the number of OopMaps in this OopMapSet226int size() const { return _om_count; }227// returns the OopMap at a given index228OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }229230// Collect OopMaps.231void add_gc_map(int pc, OopMap* map);232233// Returns the only oop map. Used for reconstructing234// Adapter frames during deoptimization235OopMap* singular_oop_map();236237// returns OopMap in that is anchored to the pc238OopMap* find_map_at_offset(int pc_offset) const;239240int heap_size() const;241void copy_to(address addr);242243// Methods oops_do() and all_do() filter out NULL oops and244// oop == Universe::narrow_oop_base() before passing oops245// to closures.246247// Iterates through frame for a compiled method248static void oops_do (const frame* fr,249const RegisterMap* reg_map, OopClosure* f);250static void update_register_map(const frame* fr, RegisterMap *reg_map);251252// Iterates through frame for a compiled method for dead ones and values, too253static void all_do(const frame* fr, const RegisterMap* reg_map,254OopClosure* oop_fn,255void derived_oop_fn(oop* base, oop* derived),256OopClosure* value_fn);257258// Printing259void print_on(outputStream* st) const;260void print() const { print_on(tty); }261};262263264class OopMapStream : public StackObj {265private:266CompressedReadStream* _stream;267int _mask;268int _size;269int _position;270bool _valid_omv;271OopMapValue _omv;272void find_next();273274public:275OopMapStream(OopMap* oop_map);276OopMapStream(OopMap* oop_map, int oop_types_mask);277bool is_done() { if(!_valid_omv) { find_next(); } return !_valid_omv; }278void next() { find_next(); }279OopMapValue current() { return _omv; }280};281282283// Derived pointer support. This table keeps track of all derived points on a284// stack. It is cleared before each scavenge/GC. During the traversal of all285// oops, it is filled in with references to all locations that contains a286// derived oop (assumed to be very few). When the GC is complete, the derived287// pointers are updated based on their base pointers new value and an offset.288#ifdef COMPILER2289class DerivedPointerTable : public AllStatic {290friend class VMStructs;291private:292static GrowableArray<DerivedPointerEntry*>* _list;293static bool _active; // do not record pointers for verify pass etc.294public:295static void clear(); // Called before scavenge/GC296static void add(oop *derived, oop *base); // Called during scavenge/GC297static void update_pointers(); // Called after scavenge/GC298static bool is_empty() { return _list == NULL || _list->is_empty(); }299static bool is_active() { return _active; }300static void set_active(bool value) { _active = value; }301};302303// A utility class to temporarily "deactivate" the DerivedPointerTable.304// (Note: clients are responsible for any MT-safety issues)305class DerivedPointerTableDeactivate: public StackObj {306private:307bool _active;308public:309DerivedPointerTableDeactivate() {310_active = DerivedPointerTable::is_active();311if (_active) {312DerivedPointerTable::set_active(false);313}314}315316~DerivedPointerTableDeactivate() {317assert(!DerivedPointerTable::is_active(),318"Inconsistency: not MT-safe");319if (_active) {320DerivedPointerTable::set_active(true);321}322}323};324#endif // COMPILER2325326#endif // SHARE_VM_COMPILER_OOPMAP_HPP327328329