hotspot/src/share/vm/oops/symbol.hpp
author ccheung
Mon, 28 Aug 2017 15:34:04 -0700
changeset 47103 a993ec29ec75
parent 46746 ea379ebb9447
permissions -rw-r--r--
8186842: Use Java class loaders for creating the CDS archive Reviewed-by: coleenp, jiangli, iklam, mseledtsov Contributed-by: calvin.cheung@oracle.com, ioi.lam@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 34666
diff changeset
     2
 * Copyright (c) 1997, 2016, 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: 4567
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
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: 4567
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
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    25
#ifndef SHARE_VM_OOPS_SYMBOL_HPP
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    26
#define SHARE_VM_OOPS_SYMBOL_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    28
#include "memory/allocation.hpp"
37466
287c4ebd11b0 8153967: Remove top.hpp
stefank
parents: 35898
diff changeset
    29
#include "utilities/exceptions.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 40016
diff changeset
    30
#include "utilities/macros.hpp"
37466
287c4ebd11b0 8153967: Remove top.hpp
stefank
parents: 35898
diff changeset
    31
#include "utilities/utf8.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    32
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    33
// A Symbol is a canonicalized string.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    34
// All Symbols reside in global SymbolTable and are reference counted.
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    36
// Reference counting
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    37
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    38
// All Symbols are allocated and added to the SymbolTable.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    39
// When a class is unloaded, the reference counts of the Symbol pointers in
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
    40
// the ConstantPool and in InstanceKlass (see release_C_heap_structures) are
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    41
// decremented.  When the reference count for a Symbol goes to 0, the garbage
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    42
// collector can free the Symbol and remove it from the SymbolTable.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    43
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    44
// 0) Symbols need to be reference counted when a pointer to the Symbol is
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    45
// saved in persistent storage.  This does not include the pointer
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    46
// in the SymbolTable bucket (the _literal field in HashtableEntry)
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    47
// that points to the Symbol.  All other stores of a Symbol*
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    48
// to a field of a persistent variable (e.g., the _name filed in
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 19696
diff changeset
    49
// fieldDescriptor or _ptr in a CPSlot) is reference counted.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    50
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    51
// 1) The lookup of a "name" in the SymbolTable either creates a Symbol F for
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    52
// "name" and returns a pointer to F or finds a pre-existing Symbol F for
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    53
// "name" and returns a pointer to it. In both cases the reference count for F
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    54
// is incremented under the assumption that a pointer to F will be created from
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    55
// the return value. Thus the increment of the reference count is on the lookup
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
// and not on the assignment to the new Symbol*.  That is
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    57
//    Symbol* G = lookup()
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
//                ^ increment on lookup()
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    59
// and not
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    60
//    Symbol* G = lookup()
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
//              ^ increment on assignmnet
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    62
// The reference count must be decremented manually when the copy of the
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    63
// pointer G is destroyed.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    64
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    65
// 2) For a local Symbol* A that is a copy of an existing Symbol* B, the
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    66
// reference counting is elided when the scope of B is greater than the scope
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    67
// of A.  For example, in the code fragment
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    68
// below "klass" is passed as a parameter to the method.  Symbol* "kn"
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    69
// is a copy of the name in "klass".
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    71
//   Symbol*  kn = klass->name();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    72
//   unsigned int d_hash = dictionary()->compute_hash(kn, class_loader);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    73
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    74
// The scope of "klass" is greater than the scope of "kn" so the reference
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    75
// counting for "kn" is elided.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    76
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    77
// Symbol* copied from ConstantPool entries are good candidates for reference
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    78
// counting elision.  The ConstantPool entries for a class C exist until C is
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    79
// unloaded.  If a Symbol* is copied out of the ConstantPool into Symbol* X,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    80
// the Symbol* in the ConstantPool will in general out live X so the reference
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    81
// counting on X can be elided.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    82
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    83
// For cases where the scope of A is not greater than the scope of B,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    84
// the reference counting is explicitly done.  See ciSymbol,
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    85
// ResolutionErrorEntry and ClassVerifier for examples.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    86
//
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    87
// 3) When a Symbol K is created for temporary use, generally for substrings of
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    88
// an existing symbol or to create a new symbol, assign it to a
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    89
// TempNewSymbol. The SymbolTable methods new_symbol(), lookup()
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    90
// and probe() all potentially return a pointer to a new Symbol.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    91
// The allocation (or lookup) of K increments the reference count for K
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    92
// and the destructor decrements the reference count.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    93
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
    94
// This cannot be inherited from ResourceObj because it cannot have a vtable.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
    95
// Since sometimes this is allocated from Metadata, pick a base allocation
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
    96
// type without virtual functions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
    97
class ClassLoaderData;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
    98
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
    99
// Set _refcount to PERM_REFCOUNT to prevent the Symbol from being GC'ed.
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   100
#ifndef PERM_REFCOUNT
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   101
#define PERM_REFCOUNT -1
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   102
#endif
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   103
32357
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   104
class Symbol : public MetaspaceObj {
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   105
  friend class VMStructs;
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   106
  friend class SymbolTable;
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   107
  friend class MoveSymbols;
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   108
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   109
 private:
18438
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15855
diff changeset
   110
  ATOMIC_SHORT_PAIR(
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15855
diff changeset
   111
    volatile short _refcount,  // needs atomic operation
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15855
diff changeset
   112
    unsigned short _length     // number of UTF8 characters in the symbol (does not need atomic op)
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15855
diff changeset
   113
  );
32357
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   114
  short _identity_hash;
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   115
  jbyte _body[2];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    // max_symbol_length is constrained by type of _length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    max_symbol_length = (1 << 16) -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  };
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   121
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   122
  static int byte_size(int length) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   123
    // minimum number of natural words needed to hold these bits (no non-heap version)
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   124
    return (int)(sizeof(Symbol) + (length > 2 ? length - 2 : 0));
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   125
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
   126
  static int size(int length) {
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 34666
diff changeset
   127
    // minimum number of natural words needed to hold these bits (no non-heap version)
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   128
    return (int)heap_word_size(byte_size(length));
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   129
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   130
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   131
  void byte_at_put(int index, int value) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   132
    assert(index >=0 && index < _length, "symbol index overflow");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   133
    _body[index] = value;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   134
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   135
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
   136
  Symbol(const u1* name, int length, int refcount);
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18438
diff changeset
   137
  void* operator new(size_t size, int len, TRAPS) throw();
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18438
diff changeset
   138
  void* operator new(size_t size, int len, Arena* arena, TRAPS) throw();
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18438
diff changeset
   139
  void* operator new(size_t size, int len, ClassLoaderData* loader_data, TRAPS) throw();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
   140
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
   141
  void  operator delete(void* p);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   142
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // Low-level access (used with care, since not GC-safe)
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   145
  const jbyte* base() const { return &_body[0]; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
   147
  int size()                { return size(utf8_length()); }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   148
  int byte_size()           { return byte_size(utf8_length()); }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   149
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   150
  // Symbols should be stored in the read-only region of CDS archive.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   151
  static bool is_read_only_by_default() { return true; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Returns the largest size symbol we can safely hold.
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33468
diff changeset
   154
  static int max_length() { return max_symbol_length; }
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33468
diff changeset
   155
  unsigned identity_hash() const {
32357
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   156
    unsigned addr_bits = (unsigned)((uintptr_t)this >> (LogMinObjAlignmentInBytes + 3));
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   157
    return ((unsigned)_identity_hash & 0xffff) |
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   158
           ((addr_bits ^ (_length << 8) ^ (( _body[0] << 8) | _body[1])) << 16);
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31790
diff changeset
   159
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
   161
  // For symbol table alternate hashing
22757
b2cbb3680b4f 8033792: AltHashing used jint for imprecise bit shifting
minqi
parents: 20017
diff changeset
   162
  unsigned int new_hash(juint seed);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12263
diff changeset
   163
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   164
  // Reference counting.  See comments above this class for when to use.
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
   165
  int refcount() const      { return _refcount; }
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 14477
diff changeset
   166
  void increment_refcount();
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 14477
diff changeset
   167
  void decrement_refcount();
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   168
  // Set _refcount non zero to avoid being reclaimed by GC.
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   169
  void set_permanent() {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   170
    assert(LogTouchedMethods, "Should not be called with LogTouchedMethods off");
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   171
    if (_refcount != PERM_REFCOUNT) {
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   172
      _refcount = PERM_REFCOUNT;
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   173
    }
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 31616
diff changeset
   174
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   175
  bool is_permanent() {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   176
    return (_refcount == PERM_REFCOUNT);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   177
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  int byte_at(int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    assert(index >=0 && index < _length, "symbol index overflow");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   181
    return base()[index];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   184
  const jbyte* bytes() const { return base(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  int utf8_length() const { return _length; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   188
  // Compares the symbol with a string.
46492
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   189
  bool equals(const char* str, int len) const {
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   190
    int l = utf8_length();
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   191
    if (l != len) return false;
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   192
    while (l-- > 0) {
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   193
      if (str[l] != (char) byte_at(l))
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   194
        return false;
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   195
    }
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   196
    assert(l == -1, "we should be at the beginning");
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   197
    return true;
5848b57c9dc5 8180763: Improve inlining of Symbol::equals(char*,int) into CompactHashtable
redestad
parents: 40655
diff changeset
   198
  }
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   199
  bool equals(const char* str) const { return equals(str, (int) strlen(str)); }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   200
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   201
  // Tests if the symbol starts with the given prefix.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   202
  bool starts_with(const char* prefix, int len) const;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   203
  bool starts_with(const char* prefix) const {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   204
    return starts_with(prefix, (int) strlen(prefix));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   205
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   206
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   207
  // Tests if the symbol starts with the given prefix.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   208
  int index_of_at(int i, const char* str, int len) const;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   209
  int index_of_at(int i, const char* str) const {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   210
    return index_of_at(i, str, (int) strlen(str));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1
diff changeset
   211
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // note that the ordering is not alfabetical
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33468
diff changeset
   215
  inline int fast_compare(const Symbol* other) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Returns receiver converted to null-terminated UTF-8 string; string is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // allocated in resource area, or in the char buffer provided by caller.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  char* as_C_string() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  char* as_C_string(char* buf, int size) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // Use buf if needed buffer length is <= size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   224
  // Returns an escaped form of a Java string.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   225
  char* as_quoted_ascii() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // Returns a null terminated utf8 string in a resource array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  char* as_utf8() const { return as_C_string(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    return as_C_string_flexible_buffer(t, buf, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  jchar* as_unicode(int& length) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  // Treating this symbol as a class name, returns the Java name for the class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // String is allocated in resource area if buffer is not provided.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // See Klass::external_name()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  const char* as_klass_external_name() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  const char* as_klass_external_name(char* buf, int size) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   241
  void metaspace_pointers_do(MetaspaceClosure* it);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   242
  MetaspaceObj::Type type() const { return SymbolType; }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   243
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   244
  // Printing
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   245
  void print_symbol_on(outputStream* st = NULL) const;
33468
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 32357
diff changeset
   246
  void print_utf8_on(outputStream* st) const;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   247
  void print_on(outputStream* st) const;         // First level print
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   248
  void print_value_on(outputStream* st) const;   // Second level print.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   249
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   250
  // printing on default output stream
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   251
  void print()         { print_on(tty);       }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   252
  void print_value()   { print_value_on(tty); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   254
#ifndef PRODUCT
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   255
  // Empty constructor to create a dummy symbol object on stack
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   256
  // only for getting its vtable pointer.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   257
  Symbol() { }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   258
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   259
  static int _total_count;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   260
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// Note: this comparison is used for vtable sorting only; it doesn't matter
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
// what order it defines, as long as it is a total, time-invariant order
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   265
// Since Symbol*s are in C_HEAP, their relative order in memory never changes,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
// so use address comparison for speed
34666
1c7168ea0034 8140485: Class load and creation cleanup
mgronlun
parents: 33468
diff changeset
   267
int Symbol::fast_compare(const Symbol* other) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
 return (((uintptr_t)this < (uintptr_t)other) ? -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
   : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   271
#endif // SHARE_VM_OOPS_SYMBOL_HPP