Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/compiler/oopMap.hpp
32285 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;45class OopClosure;4647class OopMapValue: public StackObj {48friend class VMStructs;49private:50short _value;51int value() const { return _value; }52void set_value(int value) { _value = value; }53short _content_reg;5455public:56// Constants57enum { type_bits = 5,58register_bits = BitsPerShort - type_bits };5960enum { type_shift = 0,61register_shift = type_bits };6263enum { type_mask = right_n_bits(type_bits),64type_mask_in_place = type_mask << type_shift,65register_mask = right_n_bits(register_bits),66register_mask_in_place = register_mask << register_shift };6768enum oop_types { // must fit in type_bits69unused_value =0, // powers of 2, for masking OopMapStream70oop_value = 1,71value_value = 2,72narrowoop_value = 4,73callee_saved_value = 8,74derived_oop_value= 16 };7576// Constructors77OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }78OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg, t); set_content_reg(VMRegImpl::Bad()); }79OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg, t); set_content_reg(reg2); }80OopMapValue (CompressedReadStream* stream) { read_from(stream); }8182// Archiving83void write_on(CompressedWriteStream* stream) {84stream->write_int(value());85if(is_callee_saved() || is_derived_oop()) {86stream->write_int(content_reg()->value());87}88}8990void read_from(CompressedReadStream* stream) {91set_value(stream->read_int());92if (is_callee_saved() || is_derived_oop()) {93set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));94}95}9697// Querying98bool is_oop() { return mask_bits(value(), type_mask_in_place) == oop_value; }99bool is_value() { return mask_bits(value(), type_mask_in_place) == value_value; }100bool is_narrowoop() { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }101bool is_callee_saved() { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }102bool is_derived_oop() { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }103104void set_oop() { set_value((value() & register_mask_in_place) | oop_value); }105void set_value() { set_value((value() & register_mask_in_place) | value_value); }106void set_narrowoop() { set_value((value() & register_mask_in_place) | narrowoop_value); }107void set_callee_saved() { set_value((value() & register_mask_in_place) | callee_saved_value); }108void set_derived_oop() { set_value((value() & register_mask_in_place) | derived_oop_value); }109110VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }111oop_types type() const { return (oop_types)mask_bits(value(), type_mask_in_place); }112113static bool legal_vm_reg_name(VMReg p) {114return (p->value() == (p->value() & register_mask));115}116117void set_reg_type(VMReg p, oop_types t) {118set_value((p->value() << register_shift) | t);119assert(reg() == p, "sanity check" );120assert(type() == t, "sanity check" );121}122123124VMReg content_reg() const { return VMRegImpl::as_VMReg(_content_reg, true); }125void set_content_reg(VMReg r) { _content_reg = r->value(); }126127// Physical location queries128bool is_register_loc() { return reg()->is_reg(); }129bool is_stack_loc() { return reg()->is_stack(); }130131// Returns offset from sp.132int stack_offset() {133assert(is_stack_loc(), "must be stack location");134return reg()->reg2stack();135}136137void print_on(outputStream* st) const;138void print() const { print_on(tty); }139};140141142class OopMap: public ResourceObj {143friend class OopMapStream;144friend class VMStructs;145private:146int _pc_offset;147int _omv_count;148int _omv_data_size;149unsigned char* _omv_data;150CompressedWriteStream* _write_stream;151152debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)153154// Accessors155unsigned char* omv_data() const { return _omv_data; }156void set_omv_data(unsigned char* value) { _omv_data = value; }157int omv_data_size() const { return _omv_data_size; }158void set_omv_data_size(int value) { _omv_data_size = value; }159int omv_count() const { return _omv_count; }160void set_omv_count(int value) { _omv_count = value; }161void increment_count() { _omv_count++; }162CompressedWriteStream* write_stream() const { return _write_stream; }163void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }164165private:166enum DeepCopyToken { _deep_copy_token };167OopMap(DeepCopyToken, OopMap* source); // used only by deep_copy168169public:170OopMap(int frame_size, int arg_count);171172// pc-offset handling173int offset() const { return _pc_offset; }174void set_offset(int o) { _pc_offset = o; }175176// Check to avoid double insertion177debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })178179// Construction180// frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd181// slots to hold 4-byte values like ints and floats in the LP64 build.182void set_oop ( VMReg local);183void set_value( VMReg local);184void set_narrowoop(VMReg local);185void set_dead ( VMReg local);186void set_callee_saved( VMReg local, VMReg caller_machine_register );187void set_derived_oop ( VMReg local, VMReg derived_from_local_register );188void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);189190int heap_size() const;191void copy_to(address addr);192OopMap* deep_copy();193194bool has_derived_pointer() const PRODUCT_RETURN0;195196bool legal_vm_reg_name(VMReg local) {197return OopMapValue::legal_vm_reg_name(local);198}199200// Printing201void print_on(outputStream* st) const;202void print() const { print_on(tty); }203};204205206class OopMapSet : public ResourceObj {207friend class VMStructs;208private:209int _om_count;210int _om_size;211OopMap** _om_data;212213int om_count() const { return _om_count; }214void set_om_count(int value) { _om_count = value; }215void increment_count() { _om_count++; }216int om_size() const { return _om_size; }217void set_om_size(int value) { _om_size = value; }218OopMap** om_data() const { return _om_data; }219void set_om_data(OopMap** value) { _om_data = value; }220void grow_om_data();221void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }222223public:224OopMapSet();225226// returns the number of OopMaps in this OopMapSet227int size() const { return _om_count; }228// returns the OopMap at a given index229OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }230231// Collect OopMaps.232void add_gc_map(int pc, OopMap* map);233234// Returns the only oop map. Used for reconstructing235// Adapter frames during deoptimization236OopMap* singular_oop_map();237238// returns OopMap in that is anchored to the pc239OopMap* find_map_at_offset(int pc_offset) const;240241int heap_size() const;242void copy_to(address addr);243244// Methods oops_do() and all_do() filter out NULL oops and245// oop == Universe::narrow_oop_base() before passing oops246// to closures.247248// Iterates through frame for a compiled method249static void oops_do (const frame* fr,250const RegisterMap* reg_map, OopClosure* f);251static void update_register_map(const frame* fr, RegisterMap *reg_map);252253// Iterates through frame for a compiled method for dead ones and values, too254static void all_do(const frame* fr, const RegisterMap* reg_map,255OopClosure* oop_fn,256void derived_oop_fn(oop* base, oop* derived),257OopClosure* value_fn);258259// Printing260void print_on(outputStream* st) const;261void print() const { print_on(tty); }262};263264265class OopMapStream : public StackObj {266private:267CompressedReadStream* _stream;268int _mask;269int _size;270int _position;271bool _valid_omv;272OopMapValue _omv;273void find_next();274275public:276OopMapStream(OopMap* oop_map);277OopMapStream(OopMap* oop_map, int oop_types_mask);278bool is_done() { if(!_valid_omv) { find_next(); } return !_valid_omv; }279void next() { find_next(); }280OopMapValue current() { return _omv; }281};282283284// Derived pointer support. This table keeps track of all derived points on a285// stack. It is cleared before each scavenge/GC. During the traversal of all286// oops, it is filled in with references to all locations that contains a287// derived oop (assumed to be very few). When the GC is complete, the derived288// pointers are updated based on their base pointers new value and an offset.289#ifdef COMPILER2290class DerivedPointerTable : public AllStatic {291friend class VMStructs;292private:293static GrowableArray<DerivedPointerEntry*>* _list;294static bool _active; // do not record pointers for verify pass etc.295public:296static void clear(); // Called before scavenge/GC297static void add(oop *derived, oop *base); // Called during scavenge/GC298static void update_pointers(); // Called after scavenge/GC299static bool is_empty() { return _list == NULL || _list->is_empty(); }300static bool is_active() { return _active; }301static void set_active(bool value) { _active = value; }302};303304// A utility class to temporarily "deactivate" the DerivedPointerTable.305// (Note: clients are responsible for any MT-safety issues)306class DerivedPointerTableDeactivate: public StackObj {307private:308bool _active;309public:310DerivedPointerTableDeactivate() {311_active = DerivedPointerTable::is_active();312if (_active) {313DerivedPointerTable::set_active(false);314}315}316317~DerivedPointerTableDeactivate() {318assert(!DerivedPointerTable::is_active(),319"Inconsistency: not MT-safe");320if (_active) {321DerivedPointerTable::set_active(true);322}323}324};325#endif // COMPILER2326327#endif // SHARE_VM_COMPILER_OOPMAP_HPP328329330