src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/compiler/OopMapValue.java
author never
Wed, 09 Oct 2019 16:35:44 -0700
changeset 58527 f9cc0141574c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231586: enlarge encoding space for OopMapValue offsets Reviewed-by: dlong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
     2
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.compiler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
public class OopMapValue {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  private short value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  private short contentReg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  /** Read from target VM; located in compiler/oopMap.hpp */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // How bits are organized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  static int TYPE_BITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  static int REGISTER_BITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static int TYPE_SHIFT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static int REGISTER_SHIFT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static int TYPE_MASK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  static int TYPE_MASK_IN_PLACE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  static int REGISTER_MASK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static int REGISTER_MASK_IN_PLACE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // Types of OopValues
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  static int OOP_VALUE;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    51
  static int NARROWOOP_VALUE;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  static int CALLEE_SAVED_VALUE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static int DERIVED_OOP_VALUE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private static void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    TYPE_BITS              = db.lookupIntConstant("OopMapValue::type_bits").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    REGISTER_BITS          = db.lookupIntConstant("OopMapValue::register_bits").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    TYPE_SHIFT             = db.lookupIntConstant("OopMapValue::type_shift").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    REGISTER_SHIFT         = db.lookupIntConstant("OopMapValue::register_shift").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    TYPE_MASK              = db.lookupIntConstant("OopMapValue::type_mask").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    TYPE_MASK_IN_PLACE     = db.lookupIntConstant("OopMapValue::type_mask_in_place").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    REGISTER_MASK          = db.lookupIntConstant("OopMapValue::register_mask").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    REGISTER_MASK_IN_PLACE = db.lookupIntConstant("OopMapValue::register_mask_in_place").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    OOP_VALUE              = db.lookupIntConstant("OopMapValue::oop_value").intValue();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    73
    NARROWOOP_VALUE        = db.lookupIntConstant("OopMapValue::narrowoop_value").intValue();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    CALLEE_SAVED_VALUE     = db.lookupIntConstant("OopMapValue::callee_saved_value").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    DERIVED_OOP_VALUE      = db.lookupIntConstant("OopMapValue::derived_oop_value").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  public static abstract class OopTypes {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    public static final OopTypes OOP_VALUE          = new OopTypes() { int getValue() { return OopMapValue.OOP_VALUE;          }};
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    80
    public static final OopTypes NARROWOOP_VALUE    = new OopTypes() { int getValue() { return OopMapValue.NARROWOOP_VALUE;         }};
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    public static final OopTypes CALLEE_SAVED_VALUE = new OopTypes() { int getValue() { return OopMapValue.CALLEE_SAVED_VALUE; }};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    public static final OopTypes DERIVED_OOP_VALUE  = new OopTypes() { int getValue() { return OopMapValue.DERIVED_OOP_VALUE;  }};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    abstract int getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    protected OopTypes() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  public OopMapValue()                                  { setValue((short) 0); setContentReg(new VMReg(0)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  public OopMapValue(VMReg reg, OopTypes t)             { setReg(reg); setType(t);                      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public OopMapValue(VMReg reg, OopTypes t, VMReg reg2) { setReg(reg); setType(t); setContentReg(reg2); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  public OopMapValue(CompressedReadStream stream)       { readFrom(stream);                             }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  public void readFrom(CompressedReadStream stream) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    setValue((short) stream.readInt());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    if (isCalleeSaved() || isDerivedOop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      setContentReg(new VMReg(stream.readInt()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Querying
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  public boolean isOop()         { return (getValue() & TYPE_MASK_IN_PLACE) == OOP_VALUE;          }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   102
  public boolean isNarrowOop()   { return (getValue() & TYPE_MASK_IN_PLACE) == NARROWOOP_VALUE;    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  public boolean isCalleeSaved() { return (getValue() & TYPE_MASK_IN_PLACE) == CALLEE_SAVED_VALUE; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  public boolean isDerivedOop()  { return (getValue() & TYPE_MASK_IN_PLACE) == DERIVED_OOP_VALUE;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public VMReg getReg() { return new VMReg((getValue() & REGISTER_MASK_IN_PLACE) >> REGISTER_SHIFT); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  public void  setReg(VMReg r) { setValue((short) (r.getValue() << REGISTER_SHIFT | (getValue() & TYPE_MASK_IN_PLACE))); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  public OopTypes getType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    int which = (getValue() & TYPE_MASK_IN_PLACE);
58527
f9cc0141574c 8231586: enlarge encoding space for OopMapValue offsets
never
parents: 47216
diff changeset
   111
         if (which == OOP_VALUE)    return OopTypes.OOP_VALUE;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   112
    else if (which == NARROWOOP_VALUE)   return OopTypes.NARROWOOP_VALUE;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    else if (which == CALLEE_SAVED_VALUE) return OopTypes.CALLEE_SAVED_VALUE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    else if (which == DERIVED_OOP_VALUE)  return OopTypes.DERIVED_OOP_VALUE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    else throw new InternalError("unknown which " + which + " (TYPE_MASK_IN_PLACE = " + TYPE_MASK_IN_PLACE + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  public void setType(OopTypes t) { setValue((short) ((getValue() & REGISTER_MASK_IN_PLACE) | t.getValue())); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  public VMReg getContentReg()        { return new VMReg(contentReg); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  public void  setContentReg(VMReg r) { contentReg = (short) r.getValue(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  /** Physical location queries */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  public boolean isRegisterLoc()      { return (getReg().lessThan(VM.getVM().getVMRegImplInfo().getStack0())); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  public boolean isStackLoc()         { return (getReg().greaterThanOrEqual(VM.getVM().getVMRegImplInfo().getStack0())); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  /** Returns offset from sp. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  public int getStackOffset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      Assert.that(isStackLoc(), "must be stack location");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    return getReg().minus(VM.getVM().getVMRegImplInfo().getStack0());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  private void setValue(short value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    this.value = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  private int getValue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    return value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}