hotspot/src/share/vm/oops/symbol.cpp
author twisti
Tue, 24 Jul 2012 10:51:00 -0700
changeset 13391 30245956af37
parent 13195 be27e1b6a4b9
child 13728 882756847a04
permissions -rw-r--r--
7023639: JSR 292 method handle invocation needs a fast path for compiled code 6984705: JSR 292 method handle creation should not go through JNI Summary: remove assembly code for JDK 7 chained method handles Reviewed-by: jrose, twisti, kvn, mhaupt Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
     2
 * Copyright (c) 1997, 2012, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "oops/oop.inline.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    28
#include "oops/symbol.hpp"
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    29
#include "runtime/os.hpp"
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    30
#include "memory/allocation.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    32
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
    33
  _identity_hash = os::random();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    34
  for (int i = 0; i < _length; i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    35
    byte_at_put(i, name[i]);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    36
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    37
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    38
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    39
void* Symbol::operator new(size_t sz, int len, TRAPS) {
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    40
  int alloc_size = object_size(len)*HeapWordSize;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12263
diff changeset
    41
  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
    42
  DEBUG_ONLY(set_allocation_type(res, ResourceObj::C_HEAP);)
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    43
  return res;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    44
}
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    45
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    46
void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) {
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    47
  int alloc_size = object_size(len)*HeapWordSize;
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    48
  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
    49
  DEBUG_ONLY(set_allocation_type(res, ResourceObj::ARENA);)
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
    50
  return res;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    51
}
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    52
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    53
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    54
// Symbol::equals
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    55
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    56
// 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
    57
bool Symbol::equals(const char* str, int len) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int l = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  if (l != len) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  while (l-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    if (str[l] != (char) byte_at(l))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  assert(l == -1, "we should be at the beginning");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    68
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    69
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    70
// Symbol::starts_with
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    71
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    72
// 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
    73
// length.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    74
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
    75
  if (len > utf8_length()) return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    76
  while (len-- > 0) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    77
    if (prefix[len] != (char) byte_at(len))
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    78
      return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    79
  }
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    80
  assert(len == -1, "we should be at the beginning");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    81
  return true;
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
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    84
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    85
// ------------------------------------------------------------------
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    86
// Symbol::index_of
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    87
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    88
// 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
    89
// 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
    90
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
    91
  assert(i >= 0 && i <= utf8_length(), "oob");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    92
  if (len <= 0)  return 0;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    93
  char first_char = str[0];
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    94
  address bytes = (address) ((Symbol*)this)->base();
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    95
  address limit = bytes + utf8_length() - len;  // inclusive limit
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    96
  address scan = bytes + i;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    97
  if (scan > limit)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
    98
    return -1;
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
    99
  for (; scan <= limit; scan++) {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   100
    scan = (address) memchr(scan, first_char, (limit + 1 - scan));
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   101
    if (scan == NULL)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   102
      return -1;  // not found
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   103
    assert(scan >= bytes+i && scan <= limit, "scan oob");
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   104
    if (memcmp(scan, str, len) == 0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   105
      return (int)(scan - bytes);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   106
  }
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 13195
diff changeset
   107
  return -1;
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   108
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   109
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 768
diff changeset
   110
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   111
char* Symbol::as_C_string(char* buf, int size) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    int len = MIN2(size - 1, utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    for (int i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      buf[i] = byte_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    buf[len] = '\0';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   122
char* Symbol::as_C_string() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  int len = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  char* str = NEW_RESOURCE_ARRAY(char, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  return as_C_string(str, len + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   128
char* Symbol::as_C_string_flexible_buffer(Thread* t,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
                                                 char* buf, int size) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  char* str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  int len = utf8_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  int buf_len = len + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  if (size < buf_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    str = NEW_RESOURCE_ARRAY(char, buf_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    str = buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  return as_C_string(str, buf_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   141
void Symbol::print_symbol_on(outputStream* st) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  st = st ? st : tty;
768
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   143
  int length = UTF8::unicode_length((const char*)bytes(), utf8_length());
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   144
  const char *ptr = (const char *)bytes();
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   145
  jchar value;
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   146
  for (int index = 0; index < length; index++) {
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   147
    ptr = UTF8::next(ptr, &value);
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   148
    if (value >= 32 && value < 127 || value == '\'' || value == '\\') {
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   149
      st->put(value);
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   150
    } else {
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   151
      st->print("\\u%04x", value);
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   152
    }
d0bebc7eefc2 6718676: putback for 6604014 is incomplete
never
parents: 1
diff changeset
   153
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   156
jchar* Symbol::as_unicode(int& length) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   157
  Symbol* this_ptr = (Symbol*)this;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  jchar* result = NEW_RESOURCE_ARRAY(jchar, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  if (length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   166
const char* Symbol::as_klass_external_name(char* buf, int size) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    char* str    = as_C_string(buf, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    int   length = (int)strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    // Turn all '/'s into '.'s (also for array klasses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      if (str[index] == '/') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        str[index] = '.';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return buf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   182
const char* Symbol::as_klass_external_name() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  char* str    = as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  int   length = (int)strlen(str);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Turn all '/'s into '.'s (also for array klasses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  for (int index = 0; index < length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    if (str[index] == '/') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      str[index] = '.';
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  return str;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   193
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   194
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   195
void Symbol::print_on(outputStream* st) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   196
  if (this == NULL) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   197
    st->print_cr("NULL");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   198
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   199
    st->print("Symbol: '");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   200
    print_symbol_on(st);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   201
    st->print("'");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   202
    st->print(" count %d", refcount());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   203
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   204
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   205
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   206
// 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
   207
// disassembler and error reporting.
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   208
void Symbol::print_value_on(outputStream* st) const {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   209
  if (this == NULL) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   210
    st->print("NULL");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   211
  } else {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   212
    st->print("'");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   213
    for (int i = 0; i < utf8_length(); i++) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   214
      st->print("%c", byte_at(i));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   215
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   216
    st->print("'");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   217
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   218
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   219
12263
d20640f4f8fe 7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents: 8921
diff changeset
   220
// SymbolTable prints this in its statistics
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   221
NOT_PRODUCT(int Symbol::_total_count = 0;)