Wed, 01 May 2013 08:07:59 -0700
8013418: assert(i == total_args_passed) in AdapterHandlerLibrary::get_adapter since 8-b87
Summary: Do not treat static methods as miranda methods.
Reviewed-by: dholmes, acorn
duke@435 | 1 | /* |
simonis@4675 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
coleenp@2497 | 25 | |
stefank@2314 | 26 | #include "precompiled.hpp" |
coleenp@4037 | 27 | #include "classfile/altHashing.hpp" |
coleenp@4037 | 28 | #include "classfile/classLoaderData.hpp" |
coleenp@2497 | 29 | #include "oops/symbol.hpp" |
simonis@4675 | 30 | #include "runtime/atomic.inline.hpp" |
coleenp@2497 | 31 | #include "runtime/os.hpp" |
coleenp@2497 | 32 | #include "memory/allocation.inline.hpp" |
coleenp@4037 | 33 | #include "memory/resourceArea.hpp" |
duke@435 | 34 | |
coleenp@3682 | 35 | Symbol::Symbol(const u1* name, int length, int refcount) : _refcount(refcount), _length(length) { |
coleenp@2497 | 36 | _identity_hash = os::random(); |
coleenp@2497 | 37 | for (int i = 0; i < _length; i++) { |
coleenp@2497 | 38 | byte_at_put(i, name[i]); |
coleenp@2497 | 39 | } |
coleenp@2497 | 40 | } |
coleenp@2497 | 41 | |
coleenp@3682 | 42 | void* Symbol::operator new(size_t sz, int len, TRAPS) { |
coleenp@4037 | 43 | int alloc_size = size(len)*HeapWordSize; |
zgu@3900 | 44 | address res = (address) AllocateHeap(alloc_size, mtSymbol); |
coleenp@3682 | 45 | return res; |
coleenp@3682 | 46 | } |
coleenp@3682 | 47 | |
coleenp@3682 | 48 | void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) { |
coleenp@4037 | 49 | int alloc_size = size(len)*HeapWordSize; |
coleenp@3682 | 50 | address res = (address)arena->Amalloc(alloc_size); |
coleenp@3682 | 51 | return res; |
coleenp@2497 | 52 | } |
twisti@1573 | 53 | |
coleenp@4037 | 54 | void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) { |
coleenp@4037 | 55 | address res; |
coleenp@4037 | 56 | int alloc_size = size(len)*HeapWordSize; |
coleenp@4037 | 57 | res = (address) Metaspace::allocate(loader_data, size(len), true, |
coleenp@4037 | 58 | Metaspace::NonClassType, CHECK_NULL); |
coleenp@4037 | 59 | return res; |
coleenp@4037 | 60 | } |
coleenp@4037 | 61 | |
coleenp@4037 | 62 | void Symbol::operator delete(void *p) { |
coleenp@4037 | 63 | assert(((Symbol*)p)->refcount() == 0, "should not call this"); |
coleenp@4037 | 64 | FreeHeap(p); |
coleenp@4037 | 65 | } |
coleenp@4037 | 66 | |
twisti@1573 | 67 | // ------------------------------------------------------------------ |
coleenp@2497 | 68 | // Symbol::equals |
twisti@1573 | 69 | // |
twisti@1573 | 70 | // Compares the symbol with a string of the given length. |
coleenp@2497 | 71 | bool Symbol::equals(const char* str, int len) const { |
duke@435 | 72 | int l = utf8_length(); |
duke@435 | 73 | if (l != len) return false; |
duke@435 | 74 | while (l-- > 0) { |
duke@435 | 75 | if (str[l] != (char) byte_at(l)) |
duke@435 | 76 | return false; |
duke@435 | 77 | } |
duke@435 | 78 | assert(l == -1, "we should be at the beginning"); |
duke@435 | 79 | return true; |
duke@435 | 80 | } |
duke@435 | 81 | |
twisti@1573 | 82 | |
twisti@1573 | 83 | // ------------------------------------------------------------------ |
coleenp@2497 | 84 | // Symbol::starts_with |
twisti@1573 | 85 | // |
twisti@1573 | 86 | // Tests if the symbol starts with the specified prefix of the given |
twisti@1573 | 87 | // length. |
coleenp@2497 | 88 | bool Symbol::starts_with(const char* prefix, int len) const { |
twisti@1573 | 89 | if (len > utf8_length()) return false; |
twisti@1573 | 90 | while (len-- > 0) { |
twisti@1573 | 91 | if (prefix[len] != (char) byte_at(len)) |
twisti@1573 | 92 | return false; |
twisti@1573 | 93 | } |
twisti@1573 | 94 | assert(len == -1, "we should be at the beginning"); |
twisti@1573 | 95 | return true; |
twisti@1573 | 96 | } |
twisti@1573 | 97 | |
twisti@1573 | 98 | |
twisti@1573 | 99 | // ------------------------------------------------------------------ |
coleenp@2497 | 100 | // Symbol::index_of |
twisti@1573 | 101 | // |
twisti@1573 | 102 | // Finds if the given string is a substring of this symbol's utf8 bytes. |
twisti@1573 | 103 | // Return -1 on failure. Otherwise return the first index where str occurs. |
coleenp@2497 | 104 | int Symbol::index_of_at(int i, const char* str, int len) const { |
twisti@1573 | 105 | assert(i >= 0 && i <= utf8_length(), "oob"); |
twisti@1573 | 106 | if (len <= 0) return 0; |
twisti@1573 | 107 | char first_char = str[0]; |
coleenp@2497 | 108 | address bytes = (address) ((Symbol*)this)->base(); |
twisti@1573 | 109 | address limit = bytes + utf8_length() - len; // inclusive limit |
twisti@1573 | 110 | address scan = bytes + i; |
twisti@1573 | 111 | if (scan > limit) |
twisti@1573 | 112 | return -1; |
twisti@3969 | 113 | for (; scan <= limit; scan++) { |
twisti@1573 | 114 | scan = (address) memchr(scan, first_char, (limit + 1 - scan)); |
twisti@1573 | 115 | if (scan == NULL) |
twisti@1573 | 116 | return -1; // not found |
twisti@1573 | 117 | assert(scan >= bytes+i && scan <= limit, "scan oob"); |
twisti@1573 | 118 | if (memcmp(scan, str, len) == 0) |
twisti@1573 | 119 | return (int)(scan - bytes); |
twisti@1573 | 120 | } |
twisti@3969 | 121 | return -1; |
twisti@1573 | 122 | } |
twisti@1573 | 123 | |
twisti@1573 | 124 | |
coleenp@2497 | 125 | char* Symbol::as_C_string(char* buf, int size) const { |
duke@435 | 126 | if (size > 0) { |
duke@435 | 127 | int len = MIN2(size - 1, utf8_length()); |
duke@435 | 128 | for (int i = 0; i < len; i++) { |
duke@435 | 129 | buf[i] = byte_at(i); |
duke@435 | 130 | } |
duke@435 | 131 | buf[len] = '\0'; |
duke@435 | 132 | } |
duke@435 | 133 | return buf; |
duke@435 | 134 | } |
duke@435 | 135 | |
coleenp@2497 | 136 | char* Symbol::as_C_string() const { |
duke@435 | 137 | int len = utf8_length(); |
duke@435 | 138 | char* str = NEW_RESOURCE_ARRAY(char, len + 1); |
duke@435 | 139 | return as_C_string(str, len + 1); |
duke@435 | 140 | } |
duke@435 | 141 | |
coleenp@2497 | 142 | char* Symbol::as_C_string_flexible_buffer(Thread* t, |
duke@435 | 143 | char* buf, int size) const { |
duke@435 | 144 | char* str; |
duke@435 | 145 | int len = utf8_length(); |
duke@435 | 146 | int buf_len = len + 1; |
duke@435 | 147 | if (size < buf_len) { |
duke@435 | 148 | str = NEW_RESOURCE_ARRAY(char, buf_len); |
duke@435 | 149 | } else { |
duke@435 | 150 | str = buf; |
duke@435 | 151 | } |
duke@435 | 152 | return as_C_string(str, buf_len); |
duke@435 | 153 | } |
duke@435 | 154 | |
coleenp@2497 | 155 | void Symbol::print_symbol_on(outputStream* st) const { |
vlivanov@4531 | 156 | ResourceMark rm; |
duke@435 | 157 | st = st ? st : tty; |
minqi@4267 | 158 | st->print("%s", as_quoted_ascii()); |
minqi@4267 | 159 | } |
minqi@4267 | 160 | |
minqi@4267 | 161 | char* Symbol::as_quoted_ascii() const { |
minqi@4267 | 162 | const char *ptr = (const char *)&_body[0]; |
minqi@4267 | 163 | int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length()); |
minqi@4267 | 164 | char* result = NEW_RESOURCE_ARRAY(char, quoted_length + 1); |
iklam@4851 | 165 | UTF8::as_quoted_ascii(ptr, utf8_length(), result, quoted_length + 1); |
minqi@4267 | 166 | return result; |
duke@435 | 167 | } |
duke@435 | 168 | |
coleenp@2497 | 169 | jchar* Symbol::as_unicode(int& length) const { |
coleenp@2497 | 170 | Symbol* this_ptr = (Symbol*)this; |
duke@435 | 171 | length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); |
duke@435 | 172 | jchar* result = NEW_RESOURCE_ARRAY(jchar, length); |
duke@435 | 173 | if (length > 0) { |
duke@435 | 174 | UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); |
duke@435 | 175 | } |
duke@435 | 176 | return result; |
duke@435 | 177 | } |
duke@435 | 178 | |
coleenp@2497 | 179 | const char* Symbol::as_klass_external_name(char* buf, int size) const { |
duke@435 | 180 | if (size > 0) { |
duke@435 | 181 | char* str = as_C_string(buf, size); |
duke@435 | 182 | int length = (int)strlen(str); |
duke@435 | 183 | // Turn all '/'s into '.'s (also for array klasses) |
duke@435 | 184 | for (int index = 0; index < length; index++) { |
duke@435 | 185 | if (str[index] == '/') { |
duke@435 | 186 | str[index] = '.'; |
duke@435 | 187 | } |
duke@435 | 188 | } |
duke@435 | 189 | return str; |
duke@435 | 190 | } else { |
duke@435 | 191 | return buf; |
duke@435 | 192 | } |
duke@435 | 193 | } |
duke@435 | 194 | |
coleenp@2497 | 195 | const char* Symbol::as_klass_external_name() const { |
duke@435 | 196 | char* str = as_C_string(); |
duke@435 | 197 | int length = (int)strlen(str); |
duke@435 | 198 | // Turn all '/'s into '.'s (also for array klasses) |
duke@435 | 199 | for (int index = 0; index < length; index++) { |
duke@435 | 200 | if (str[index] == '/') { |
duke@435 | 201 | str[index] = '.'; |
duke@435 | 202 | } |
duke@435 | 203 | } |
duke@435 | 204 | return str; |
duke@435 | 205 | } |
coleenp@2497 | 206 | |
coleenp@4037 | 207 | // Alternate hashing for unbalanced symbol tables. |
coleenp@4037 | 208 | unsigned int Symbol::new_hash(jint seed) { |
coleenp@4037 | 209 | ResourceMark rm; |
coleenp@4037 | 210 | // Use alternate hashing algorithm on this symbol. |
coleenp@4037 | 211 | return AltHashing::murmur3_32(seed, (const jbyte*)as_C_string(), utf8_length()); |
coleenp@4037 | 212 | } |
coleenp@2497 | 213 | |
simonis@4675 | 214 | void Symbol::increment_refcount() { |
simonis@4675 | 215 | // Only increment the refcount if positive. If negative either |
simonis@4675 | 216 | // overflow has occurred or it is a permanent symbol in a read only |
simonis@4675 | 217 | // shared archive. |
simonis@4675 | 218 | if (_refcount >= 0) { |
simonis@4675 | 219 | Atomic::inc(&_refcount); |
simonis@4675 | 220 | NOT_PRODUCT(Atomic::inc(&_total_count);) |
simonis@4675 | 221 | } |
simonis@4675 | 222 | } |
simonis@4675 | 223 | |
simonis@4675 | 224 | void Symbol::decrement_refcount() { |
simonis@4675 | 225 | if (_refcount >= 0) { |
simonis@4675 | 226 | Atomic::dec(&_refcount); |
simonis@4675 | 227 | #ifdef ASSERT |
simonis@4675 | 228 | if (_refcount < 0) { |
simonis@4675 | 229 | print(); |
simonis@4675 | 230 | assert(false, "reference count underflow for symbol"); |
simonis@4675 | 231 | } |
simonis@4675 | 232 | #endif |
simonis@4675 | 233 | } |
simonis@4675 | 234 | } |
simonis@4675 | 235 | |
coleenp@2497 | 236 | void Symbol::print_on(outputStream* st) const { |
coleenp@2497 | 237 | if (this == NULL) { |
coleenp@2497 | 238 | st->print_cr("NULL"); |
coleenp@2497 | 239 | } else { |
coleenp@2497 | 240 | st->print("Symbol: '"); |
coleenp@2497 | 241 | print_symbol_on(st); |
coleenp@2497 | 242 | st->print("'"); |
coleenp@2497 | 243 | st->print(" count %d", refcount()); |
coleenp@2497 | 244 | } |
coleenp@2497 | 245 | } |
coleenp@2497 | 246 | |
coleenp@2497 | 247 | // The print_value functions are present in all builds, to support the |
coleenp@2497 | 248 | // disassembler and error reporting. |
coleenp@2497 | 249 | void Symbol::print_value_on(outputStream* st) const { |
coleenp@2497 | 250 | if (this == NULL) { |
coleenp@2497 | 251 | st->print("NULL"); |
coleenp@2497 | 252 | } else { |
coleenp@2497 | 253 | st->print("'"); |
coleenp@2497 | 254 | for (int i = 0; i < utf8_length(); i++) { |
coleenp@2497 | 255 | st->print("%c", byte_at(i)); |
coleenp@2497 | 256 | } |
coleenp@2497 | 257 | st->print("'"); |
coleenp@2497 | 258 | } |
coleenp@2497 | 259 | } |
coleenp@2497 | 260 | |
coleenp@3682 | 261 | // SymbolTable prints this in its statistics |
coleenp@2497 | 262 | NOT_PRODUCT(int Symbol::_total_count = 0;) |