src/hotspot/share/oops/symbol.cpp
author stefank
Mon, 25 Nov 2019 12:33:15 +0100
changeset 59252 623722a6aeb9
parent 58722 cba8afa5cfed
permissions -rw-r--r--
8234740: Harmonize parameter order in Atomic - cmpxchg Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53156
488773472a63 8216197: Remove unused new_hash methods
redestad
parents: 52190
diff changeset
     2
 * Copyright (c) 1997, 2019, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "precompiled.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    27
#include "classfile/altHashing.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    28
#include "classfile/classLoaderData.hpp"
52014
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
    29
#include "gc/shared/collectedHeap.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
    30
#include "logging/log.hpp"
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
    31
#include "logging/logStream.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 22757
diff changeset
    32
#include "memory/allocation.inline.hpp"
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 22757
diff changeset
    33
#include "memory/resourceArea.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54432
diff changeset
    34
#include "memory/universe.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    35
#include "oops/symbol.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 36570
diff changeset
    36
#include "runtime/atomic.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    37
#include "runtime/os.hpp"
54347
235883996bc7 8221698: Remove redundant includes from popular header files
iklam
parents: 54133
diff changeset
    38
#include "utilities/utf8.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    40
uint32_t Symbol::pack_length_and_refcount(int length, int refcount) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    41
  STATIC_ASSERT(max_symbol_length == ((1 << 16) - 1));
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    42
  STATIC_ASSERT(PERM_REFCOUNT == ((1 << 16) - 1));
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    43
  assert(length >= 0, "negative length");
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    44
  assert(length <= max_symbol_length, "too long symbol");
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    45
  assert(refcount >= 0, "negative refcount");
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    46
  assert(refcount <= PERM_REFCOUNT, "invalid refcount");
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    47
  uint32_t hi = length;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    48
  uint32_t lo = refcount;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    49
  return (hi << 16) | lo;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    50
}
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    51
18438
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 17858
diff changeset
    52
Symbol::Symbol(const u1* name, int length, int refcount) {
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    53
  _length_and_refcount =  pack_length_and_refcount(length, refcount);
32357
43087bc6dd04 8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents: 31616
diff changeset
    54
  _identity_hash = (short)os::random();
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
    55
  for (int i = 0; i < length; i++) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    56
    byte_at_put(i, name[i]);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    57
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    58
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    59
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54807
diff changeset
    60
void* Symbol::operator new(size_t sz, int len) throw() {
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 33468
diff changeset
    61
  int alloc_size = size(len)*wordSize;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12263
diff changeset
    62
  address res = (address) AllocateHeap(alloc_size, mtSymbol);
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    63
  return res;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    64
}
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    65
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54807
diff changeset
    66
void* Symbol::operator new(size_t sz, int len, Arena* arena) throw() {
35898
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 33468
diff changeset
    67
  int alloc_size = size(len)*wordSize;
ddc274f0052f 8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents: 33468
diff changeset
    68
  address res = (address)arena->Amalloc_4(alloc_size);
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    69
  return res;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
}
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    71
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    72
void Symbol::operator delete(void *p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    73
  assert(((Symbol*)p)->refcount() == 0, "should not call this");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    74
  FreeHeap(p);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    75
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    76
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    77
void Symbol::set_permanent() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    78
  // This is called at a safepoint during dumping of a dynamic CDS archive.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    79
  assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    80
  _length_and_refcount =  pack_length_and_refcount(length(), PERM_REFCOUNT);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    81
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    82
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54847
diff changeset
    83
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    84
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    85
// Symbol::starts_with
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    86
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    87
// Tests if the symbol starts with the specified prefix of the given
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    88
// length.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    89
bool Symbol::starts_with(const char* prefix, int len) const {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    90
  if (len > utf8_length()) return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    91
  while (len-- > 0) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51405
diff changeset
    92
    if (prefix[len] != char_at(len))
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    93
      return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    94
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    95
  assert(len == -1, "we should be at the beginning");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    96
  return true;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    97
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    98
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    99
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   100
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   101
// Symbol::index_of
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   102
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   103
// Finds if the given string is a substring of this symbol's utf8 bytes.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   104
// Return -1 on failure.  Otherwise return the first index where str occurs.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   105
int Symbol::index_of_at(int i, const char* str, int len) const {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   106
  assert(i >= 0 && i <= utf8_length(), "oob");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   107
  if (len <= 0)  return 0;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   108
  char first_char = str[0];
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   109
  address bytes = (address) ((Symbol*)this)->base();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   110
  address limit = bytes + utf8_length() - len;  // inclusive limit
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   111
  address scan = bytes + i;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   112
  if (scan > limit)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   113
    return -1;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   114
  for (; scan <= limit; scan++) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   115
    scan = (address) memchr(scan, first_char, (limit + 1 - scan));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   116
    if (scan == NULL)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   117
      return -1;  // not found
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   118
    assert(scan >= bytes+i && scan <= limit, "scan oob");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   119
    if (memcmp(scan, str, len) == 0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   120
      return (int)(scan - bytes);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   121
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   122
  return -1;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   123
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   124
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   125
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   126
char* Symbol::as_C_string(char* buf, int size) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    int len = MIN2(size - 1, utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    for (int i = 0; i < len; i++) {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 51405
diff changeset
   130
      buf[i] = char_at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    buf[len] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   137
char* Symbol::as_C_string() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  int len = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  char* str = NEW_RESOURCE_ARRAY(char, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  return as_C_string(str, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
33468
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 32357
diff changeset
   143
void Symbol::print_utf8_on(outputStream* st) const {
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 32357
diff changeset
   144
  st->print("%s", as_C_string());
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 32357
diff changeset
   145
}
b82c87453d2d 8139996: CompileCommand prints quoted ascii strings
neliasso
parents: 32357
diff changeset
   146
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   147
void Symbol::print_symbol_on(outputStream* st) const {
36570
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   148
  char *s;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  st = st ? st : tty;
36570
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   150
  {
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   151
    // ResourceMark may not affect st->print(). If st is a string
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   152
    // stream it could resize, using the same resource arena.
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   153
    ResourceMark rm;
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   154
    s = as_quoted_ascii();
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   155
    s = os::strdup(s);
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   156
  }
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   157
  if (s == NULL) {
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   158
    st->print("(null)");
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   159
  } else {
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   160
    st->print("%s", s);
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   161
    os::free(s);
9608a7830fe9 8149557: Resource mark breaks printing to string stream
goetz
parents: 35898
diff changeset
   162
  }
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   163
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   164
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   165
char* Symbol::as_quoted_ascii() const {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   166
  const char *ptr = (const char *)&_body[0];
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   167
  int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   168
  char* result = NEW_RESOURCE_ARRAY(char, quoted_length + 1);
16602
5df51d3bc550 8011048: Possible reading from unmapped memory in UTF8::as_quoted_ascii()
iklam
parents: 15855
diff changeset
   169
  UTF8::as_quoted_ascii(ptr, utf8_length(), result, quoted_length + 1);
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   170
  return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   173
jchar* Symbol::as_unicode(int& length) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   174
  Symbol* this_ptr = (Symbol*)this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  if (length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   183
const char* Symbol::as_klass_external_name(char* buf, int size) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    char* str    = as_C_string(buf, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    int   length = (int)strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    // Turn all '/'s into '.'s (also for array klasses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      if (str[index] == '/') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        str[index] = '.';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   199
const char* Symbol::as_klass_external_name() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  char* str    = as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  int   length = (int)strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // Turn all '/'s into '.'s (also for array klasses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  for (int index = 0; index < length; index++) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58015
diff changeset
   204
    if (str[index] == JVM_SIGNATURE_SLASH) {
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58015
diff changeset
   205
      str[index] = JVM_SIGNATURE_DOT;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
}
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   210
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   211
static void print_class(outputStream *os, char *class_str, int len) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   212
  for (int i = 0; i < len; ++i) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58015
diff changeset
   213
    if (class_str[i] == JVM_SIGNATURE_SLASH) {
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58015
diff changeset
   214
      os->put(JVM_SIGNATURE_DOT);
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   215
    } else {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   216
      os->put(class_str[i]);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   217
    }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   218
  }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   219
}
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   220
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   221
static void print_array(outputStream *os, char *array_str, int len) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   222
  int dimensions = 0;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   223
  for (int i = 0; i < len; ++i) {
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58015
diff changeset
   224
    if (array_str[i] == JVM_SIGNATURE_ARRAY) {
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   225
      dimensions++;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 58015
diff changeset
   226
    } else if (array_str[i] == JVM_SIGNATURE_CLASS) {
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   227
      // Expected format: L<type name>;. Skip 'L' and ';' delimiting the type name.
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   228
      print_class(os, array_str+i+1, len-i-2);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   229
      break;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   230
    } else {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   231
      os->print("%s", type2name(char2type(array_str[i])));
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   232
    }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   233
  }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   234
  for (int i = 0; i < dimensions; ++i) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   235
    os->print("[]");
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   236
  }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   237
}
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   238
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   239
void Symbol::print_as_signature_external_return_type(outputStream *os) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   240
  for (SignatureStream ss(this); !ss.is_done(); ss.next()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   241
    if (ss.at_return_type()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   242
      if (ss.is_array()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   243
        print_array(os, (char*)ss.raw_bytes(), (int)ss.raw_length());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   244
      } else if (ss.is_object()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   245
        // Expected format: L<type name>;. Skip 'L' and ';' delimiting the class name.
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   246
        print_class(os, (char*)ss.raw_bytes()+1, (int)ss.raw_length()-2);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   247
      } else {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   248
        os->print("%s", type2name(ss.type()));
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   249
      }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   250
    }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   251
  }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   252
}
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   253
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   254
void Symbol::print_as_signature_external_parameters(outputStream *os) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   255
  bool first = true;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   256
  for (SignatureStream ss(this); !ss.is_done(); ss.next()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   257
    if (ss.at_return_type()) break;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   258
    if (!first) { os->print(", "); }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   259
    if (ss.is_array()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   260
      print_array(os, (char*)ss.raw_bytes(), (int)ss.raw_length());
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   261
    } else if (ss.is_object()) {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   262
      // Skip 'L' and ';'.
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   263
      print_class(os, (char*)ss.raw_bytes()+1, (int)ss.raw_length()-2);
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   264
    } else {
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   265
      os->print("%s", type2name(ss.type()));
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   266
    }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   267
    first = false;
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   268
  }
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   269
}
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 54347
diff changeset
   270
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   271
// Increment refcount while checking for zero.  If the Symbol's refcount becomes zero
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   272
// a thread could be concurrently removing the Symbol.  This is used during SymbolTable
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   273
// lookup to avoid reviving a dead Symbol.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   274
bool Symbol::try_increment_refcount() {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   275
  uint32_t found = _length_and_refcount;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   276
  while (true) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   277
    uint32_t old_value = found;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   278
    int refc = extract_refcount(old_value);
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   279
    if (refc == PERM_REFCOUNT) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   280
      return true;  // sticky max or created permanent
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   281
    } else if (refc == 0) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   282
      return false; // dead, can't revive.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   283
    } else {
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 58722
diff changeset
   284
      found = Atomic::cmpxchg(&_length_and_refcount, old_value, old_value + 1);
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   285
      if (found == old_value) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   286
        return true; // successfully updated.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   287
      }
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   288
      // refcount changed, try again.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   289
    }
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   290
  }
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   291
}
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   292
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   293
// The increment_refcount() is called when not doing lookup. It is assumed that you
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   294
// have a symbol with a non-zero refcount and it can't become zero while referenced by
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   295
// this caller.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   296
void Symbol::increment_refcount() {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   297
  if (!try_increment_refcount()) {
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   298
#ifdef ASSERT
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   299
    print();
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   300
    fatal("refcount has gone to zero");
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   301
#endif
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   302
  }
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   303
#ifndef PRODUCT
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   304
  if (refcount() != PERM_REFCOUNT) { // not a permanent symbol
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   305
    NOT_PRODUCT(Atomic::inc(&_total_count);)
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   306
  }
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   307
#endif
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   308
}
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   309
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   310
// Decrement refcount potentially while racing increment, so we need
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   311
// to check the value after attempting to decrement so that if another
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   312
// thread increments to PERM_REFCOUNT the value is not decremented.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   313
void Symbol::decrement_refcount() {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   314
  uint32_t found = _length_and_refcount;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   315
  while (true) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   316
    uint32_t old_value = found;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   317
    int refc = extract_refcount(old_value);
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   318
    if (refc == PERM_REFCOUNT) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   319
      return;  // refcount is permanent, permanent is sticky
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   320
    } else if (refc == 0) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   321
#ifdef ASSERT
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   322
      print();
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   323
      fatal("refcount underflow");
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   324
#endif
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   325
      return;
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   326
    } else {
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 58722
diff changeset
   327
      found = Atomic::cmpxchg(&_length_and_refcount, old_value, old_value - 1);
51179
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   328
      if (found == old_value) {
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   329
        return;  // successfully updated.
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   330
      }
516acf6956a2 8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents: 47216
diff changeset
   331
      // refcount changed, try again.
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   332
    }
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   333
  }
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   334
}
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   335
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   336
void Symbol::make_permanent() {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   337
  uint32_t found = _length_and_refcount;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   338
  while (true) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   339
    uint32_t old_value = found;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   340
    int refc = extract_refcount(old_value);
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   341
    if (refc == PERM_REFCOUNT) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   342
      return;  // refcount is permanent, permanent is sticky
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   343
    } else if (refc == 0) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   344
#ifdef ASSERT
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   345
      print();
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   346
      fatal("refcount underflow");
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   347
#endif
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   348
      return;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   349
    } else {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   350
      int len = extract_length(old_value);
59252
623722a6aeb9 8234740: Harmonize parameter order in Atomic - cmpxchg
stefank
parents: 58722
diff changeset
   351
      found = Atomic::cmpxchg(&_length_and_refcount, old_value, pack_length_and_refcount(len, PERM_REFCOUNT));
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   352
      if (found == old_value) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   353
        return;  // successfully updated.
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   354
      }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   355
      // refcount changed, try again.
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   356
    }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   357
  }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   358
}
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 53731
diff changeset
   359
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   360
void Symbol::metaspace_pointers_do(MetaspaceClosure* it) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   361
  if (log_is_enabled(Trace, cds)) {
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   362
    LogStream trace_stream(Log(cds)::trace());
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   363
    trace_stream.print("Iter(Symbol): %p ", this);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   364
    print_value_on(&trace_stream);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   365
    trace_stream.cr();
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   366
  }
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   367
}
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46492
diff changeset
   368
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   369
void Symbol::print_on(outputStream* st) const {
52190
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   370
  st->print("Symbol: '");
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   371
  print_symbol_on(st);
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   372
  st->print("'");
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   373
  st->print(" count %d", refcount());
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   374
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   375
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   376
void Symbol::print() const { print_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   377
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   378
// The print_value functions are present in all builds, to support the
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   379
// disassembler and error reporting.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   380
void Symbol::print_value_on(outputStream* st) const {
52190
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   381
  st->print("'");
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   382
  for (int i = 0; i < utf8_length(); i++) {
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   383
    st->print("%c", char_at(i));
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   384
  }
52190
4e04b7ab20a3 8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents: 52014
diff changeset
   385
  st->print("'");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   386
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   387
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   388
void Symbol::print_value() const { print_value_on(tty); }
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54786
diff changeset
   389
52014
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   390
bool Symbol::is_valid(Symbol* s) {
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   391
  if (!is_aligned(s, sizeof(MetaWord))) return false;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   392
  if ((size_t)s < os::min_page_size()) return false;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   393
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   394
  if (!os::is_readable_range(s, s + 1)) return false;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   395
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   396
  // Symbols are not allocated in Java heap.
58015
dd84de796f2c 8224815: Remove non-GC uses of CollectedHeap::is_in_reserved()
eosterlund
parents: 54927
diff changeset
   397
  if (Universe::heap()->is_in(s)) return false;
52014
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   398
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   399
  int len = s->utf8_length();
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   400
  if (len < 0) return false;
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   401
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   402
  jbyte* bytes = (jbyte*) s->bytes();
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   403
  return os::is_readable_range(bytes, bytes + len);
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   404
}
1aa9beac610e 8210754: print_location is not reliable enough (printing register info)
mdoerr
parents: 51997
diff changeset
   405
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
   406
// SymbolTable prints this in its statistics
51405
8b23aa7cef47 8195100: Use a low latency hashtable for SymbolTable
gziemski
parents: 51179
diff changeset
   407
NOT_PRODUCT(size_t Symbol::_total_count = 0;)