hotspot/src/share/vm/oops/symbol.cpp
author simonis
Wed, 27 Feb 2013 09:40:30 +0100
changeset 15855 2ac9ebea17f3
parent 15471 41f75023e6a6
child 16602 5df51d3bc550
permissions -rw-r--r--
8008959: Fix non-PCH build on Linux, Windows and MacOS X Summary: Fix the build without precompiled headers by either including the missing ".inline.hpp" files into the appropriate files or by turning inline-functions declared in header files into ordinary functions in ".cpp" files. Reviewed-by: coleenp, stefank, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
     2
 * Copyright (c) 1997, 2013, 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"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    29
#include "oops/symbol.hpp"
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
    30
#include "runtime/atomic.inline.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    31
#include "runtime/os.hpp"
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    32
#include "memory/allocation.inline.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    33
#include "memory/resourceArea.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    35
Symbol::Symbol(const u1* name, int length, int refcount) : _refcount(refcount), _length(length) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    36
  _identity_hash = os::random();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    37
  for (int i = 0; i < _length; i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    38
    byte_at_put(i, name[i]);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    39
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    40
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    41
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    42
void* Symbol::operator new(size_t sz, int len, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    43
  int alloc_size = size(len)*HeapWordSize;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12263
diff changeset
    44
  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
    45
  return res;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    46
}
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    47
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    48
void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    49
  int alloc_size = size(len)*HeapWordSize;
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    50
  address res = (address)arena->Amalloc(alloc_size);
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    51
  return res;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    52
}
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    53
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    54
void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    55
  address res;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    56
  int alloc_size = size(len)*HeapWordSize;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    57
  res = (address) Metaspace::allocate(loader_data, size(len), true,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    58
                                      Metaspace::NonClassType, CHECK_NULL);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    59
  return res;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    60
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    61
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    62
void Symbol::operator delete(void *p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    63
  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
    64
  FreeHeap(p);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    65
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    66
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    67
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    68
// Symbol::equals
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    69
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    70
// Compares the symbol with a string of the given length.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    71
bool Symbol::equals(const char* str, int len) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  int l = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  if (l != len) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  while (l-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    if (str[l] != (char) byte_at(l))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  assert(l == -1, "we should be at the beginning");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    82
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    83
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    84
// Symbol::starts_with
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    85
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    86
// 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
    87
// length.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    88
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
    89
  if (len > utf8_length()) return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    90
  while (len-- > 0) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    91
    if (prefix[len] != (char) byte_at(len))
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    92
      return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    93
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    94
  assert(len == -1, "we should be at the beginning");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    95
  return true;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    96
}
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
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   100
// Symbol::index_of
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   101
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   102
// 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
   103
// 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
   104
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
   105
  assert(i >= 0 && i <= utf8_length(), "oob");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   106
  if (len <= 0)  return 0;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   107
  char first_char = str[0];
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   108
  address bytes = (address) ((Symbol*)this)->base();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   109
  address limit = bytes + utf8_length() - len;  // inclusive limit
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   110
  address scan = bytes + i;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   111
  if (scan > limit)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   112
    return -1;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   113
  for (; scan <= limit; scan++) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   114
    scan = (address) memchr(scan, first_char, (limit + 1 - scan));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   115
    if (scan == NULL)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   116
      return -1;  // not found
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   117
    assert(scan >= bytes+i && scan <= limit, "scan oob");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   118
    if (memcmp(scan, str, len) == 0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   119
      return (int)(scan - bytes);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   120
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   121
  return -1;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   122
}
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
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   125
char* Symbol::as_C_string(char* buf, int size) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    int len = MIN2(size - 1, utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      buf[i] = byte_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    buf[len] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   136
char* Symbol::as_C_string() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  int len = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  char* str = NEW_RESOURCE_ARRAY(char, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  return as_C_string(str, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   142
char* Symbol::as_C_string_flexible_buffer(Thread* t,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
                                                 char* buf, int size) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  char* str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  int len = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  int buf_len = len + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  if (size < buf_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    str = NEW_RESOURCE_ARRAY(char, buf_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    str = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  return as_C_string(str, buf_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   155
void Symbol::print_symbol_on(outputStream* st) const {
15471
41f75023e6a6 8006410: allocating without ResourceMark when CompileCommand was specified
vlivanov
parents: 14477
diff changeset
   156
  ResourceMark rm;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  st = st ? st : tty;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   158
  st->print("%s", as_quoted_ascii());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   159
}
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   160
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   161
char* Symbol::as_quoted_ascii() const {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   162
  const char *ptr = (const char *)&_body[0];
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   163
  int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   164
  char* result = NEW_RESOURCE_ARRAY(char, quoted_length + 1);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   165
  UTF8::as_quoted_ascii(ptr, result, quoted_length + 1);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   166
  return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   169
jchar* Symbol::as_unicode(int& length) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   170
  Symbol* this_ptr = (Symbol*)this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  if (length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   179
const char* Symbol::as_klass_external_name(char* buf, int size) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    char* str    = as_C_string(buf, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    int   length = (int)strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // Turn all '/'s into '.'s (also for array klasses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      if (str[index] == '/') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        str[index] = '.';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   195
const char* Symbol::as_klass_external_name() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  char* str    = as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  int   length = (int)strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  // Turn all '/'s into '.'s (also for array klasses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    if (str[index] == '/') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      str[index] = '.';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   206
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   207
// Alternate hashing for unbalanced symbol tables.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   208
unsigned int Symbol::new_hash(jint seed) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   209
  ResourceMark rm;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   210
  // Use alternate hashing algorithm on this symbol.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   211
  return AltHashing::murmur3_32(seed, (const jbyte*)as_C_string(), utf8_length());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   212
}
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   213
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   214
void Symbol::increment_refcount() {
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   215
  // Only increment the refcount if positive.  If negative either
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   216
  // overflow has occurred or it is a permanent symbol in a read only
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   217
  // shared archive.
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   218
  if (_refcount >= 0) {
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   219
    Atomic::inc(&_refcount);
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   220
    NOT_PRODUCT(Atomic::inc(&_total_count);)
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   221
  }
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   222
}
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   223
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   224
void Symbol::decrement_refcount() {
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   225
  if (_refcount >= 0) {
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   226
    Atomic::dec(&_refcount);
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   227
#ifdef ASSERT
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   228
    if (_refcount < 0) {
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   229
      print();
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   230
      assert(false, "reference count underflow for symbol");
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   231
    }
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   232
#endif
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   233
  }
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   234
}
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 15471
diff changeset
   235
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   236
void Symbol::print_on(outputStream* st) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   237
  if (this == NULL) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   238
    st->print_cr("NULL");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   239
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   240
    st->print("Symbol: '");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   241
    print_symbol_on(st);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   242
    st->print("'");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   243
    st->print(" count %d", refcount());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   244
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   245
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   246
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   247
// 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
   248
// disassembler and error reporting.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   249
void Symbol::print_value_on(outputStream* st) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   250
  if (this == NULL) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   251
    st->print("NULL");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   252
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   253
    st->print("'");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   254
    for (int i = 0; i < utf8_length(); i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   255
      st->print("%c", byte_at(i));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   256
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   257
    st->print("'");
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
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   260
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
   261
// SymbolTable prints this in its statistics
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   262
NOT_PRODUCT(int Symbol::_total_count = 0;)