src/hotspot/share/oops/compressedOops.hpp
author coleenp
Wed, 24 Jul 2019 10:22:11 -0400
changeset 57511 00ae3b739184
parent 54825 1b03400e5a8f
child 58015 dd84de796f2c
permissions -rw-r--r--
8228485: JVM crashes when bootstrap method for condy triggers loading of class whose static initializer throws exception Summary: Add case for JVM_CONSTANT_Dynamic in error_message function. Reviewed-by: dholmes, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     1
/*
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     4
 *
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     8
 *
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    13
 * accompanied this code).
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    14
 *
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    18
 *
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    21
 * questions.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    22
 *
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    23
 */
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    24
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    25
#ifndef SHARE_OOPS_COMPRESSEDOOPS_HPP
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    26
#define SHARE_OOPS_COMPRESSEDOOPS_HPP
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    27
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    28
#include "memory/allocation.hpp"
54825
1b03400e5a8f 8223637: Fix build breakage after 8223136
stefank
parents: 54780
diff changeset
    29
#include "oops/oopsHierarchy.hpp"
54780
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    31
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    32
class outputStream;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    33
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    34
struct NarrowPtrStruct {
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    35
  // Base address for oop-within-java-object materialization.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    36
  // NULL if using wide oops or zero based narrow oops.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    37
  address _base;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    38
  // Number of shift bits for encoding/decoding narrow ptrs.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    39
  // 0 if using wide ptrs or zero based unscaled narrow ptrs,
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    40
  // LogMinObjAlignmentInBytes/LogKlassAlignmentInBytes otherwise.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    41
  int     _shift;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    42
  // Generate code with implicit null checks for narrow ptrs.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    43
  bool    _use_implicit_null_checks;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    44
};
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    45
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    46
class CompressedOops : public AllStatic {
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    47
  friend class VMStructs;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    48
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    49
  // For UseCompressedOops.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    50
  static NarrowPtrStruct _narrow_oop;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    51
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    52
  static address _narrow_ptrs_base;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    53
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    54
public:
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    55
  // For UseCompressedOops
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    56
  // Narrow Oop encoding mode:
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    57
  // 0 - Use 32-bits oops without encoding when
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    58
  //     NarrowOopHeapBaseMin + heap_size < 4Gb
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    59
  // 1 - Use zero based compressed oops with encoding when
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    60
  //     NarrowOopHeapBaseMin + heap_size < 32Gb
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    61
  // 2 - Use compressed oops with disjoint heap base if
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    62
  //     base is 32G-aligned and base > 0. This allows certain
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    63
  //     optimizations in encoding/decoding.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    64
  //     Disjoint: Bits used in base are disjoint from bits used
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    65
  //     for oops ==> oop = (cOop << 3) | base.  One can disjoint
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    66
  //     the bits of an oop into base and compressed oop.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    67
  // 3 - Use compressed oops with heap base + encoding.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    68
  enum Mode {
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    69
    UnscaledNarrowOop  = 0,
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    70
    ZeroBasedNarrowOop = 1,
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    71
    DisjointBaseNarrowOop = 2,
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    72
    HeapBasedNarrowOop = 3,
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    73
    AnyNarrowOopMode = 4
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    74
  };
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    75
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    76
  static void initialize();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    77
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    78
  static void set_base(address base);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    79
  static void set_shift(int shift);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    80
  static void set_use_implicit_null_checks(bool use);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    81
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    82
  static void set_ptrs_base(address addr);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    83
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    84
  static address  base()                     { return  _narrow_oop._base; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    85
  static bool     is_base(void* addr)        { return (base() == (address)addr); }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    86
  static int      shift()                    { return  _narrow_oop._shift; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    87
  static bool     use_implicit_null_checks() { return  _narrow_oop._use_implicit_null_checks; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    88
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    89
  static address* ptrs_base_addr()           { return &_narrow_ptrs_base; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    90
  static address  ptrs_base()                { return _narrow_ptrs_base; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    91
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    92
  static Mode mode();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    93
  static const char* mode_to_string(Mode mode);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    94
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    95
  // Test whether bits of addr and possible offsets into the heap overlap.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    96
  static bool     is_disjoint_heap_base_address(address addr);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    97
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    98
  // Check for disjoint base compressed oops.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
    99
  static bool     base_disjoint();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   100
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   101
  // Check for real heapbased compressed oops.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   102
  // We must subtract the base as the bits overlap.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   103
  // If we negate above function, we also get unscaled and zerobased.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   104
  static bool     base_overlaps();
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   105
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   106
  static void     print_mode(outputStream* st);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   107
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   108
  static bool is_null(oop v)       { return v == NULL; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   109
  static bool is_null(narrowOop v) { return v == 0; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   110
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   111
  static inline oop decode_raw(narrowOop v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   112
  static inline oop decode_not_null(narrowOop v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   113
  static inline oop decode(narrowOop v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   114
  static inline narrowOop encode_not_null(oop v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   115
  static inline narrowOop encode(oop v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   116
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   117
  // No conversions needed for these overloads
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   118
  static oop decode_not_null(oop v)             { return v; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   119
  static oop decode(oop v)                      { return v; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   120
  static narrowOop encode_not_null(narrowOop v) { return v; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   121
  static narrowOop encode(narrowOop v)          { return v; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   122
};
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   123
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   124
// For UseCompressedClassPointers.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   125
class CompressedKlassPointers : public AllStatic {
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   126
  friend class VMStructs;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   127
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   128
  static NarrowPtrStruct _narrow_klass;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   129
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   130
  // CompressedClassSpaceSize set to 1GB, but appear 3GB away from _narrow_ptrs_base during CDS dump.
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   131
  static uint64_t _narrow_klass_range;
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   132
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   133
public:
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   134
  static void set_base(address base);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   135
  static void set_shift(int shift);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   136
  static void set_range(uint64_t range);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   137
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   138
  static address  base()               { return  _narrow_klass._base; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   139
  static uint64_t range()              { return  _narrow_klass_range; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   140
  static int      shift()              { return  _narrow_klass._shift; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   141
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   142
  static bool is_null(Klass* v)      { return v == NULL; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   143
  static bool is_null(narrowKlass v) { return v == 0; }
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   144
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   145
  static inline Klass* decode_raw(narrowKlass v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   146
  static inline Klass* decode_not_null(narrowKlass v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   147
  static inline Klass* decode(narrowKlass v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   148
  static inline narrowKlass encode_not_null(Klass* v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   149
  static inline narrowKlass encode(Klass* v);
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   150
};
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   151
f8d182aedc92 8223136: Move compressed oops functions to CompressedOops class
stefank
parents:
diff changeset
   152
#endif // SHARE_OOPS_COMPRESSEDOOPS_HPP