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 | #ifndef SHARE_VM_OOPS_SYMBOL_HPP |
coleenp@2497 | 26 | #define SHARE_VM_OOPS_SYMBOL_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "utilities/utf8.hpp" |
coleenp@2497 | 29 | #include "memory/allocation.hpp" |
stefank@2314 | 30 | |
coleenp@2497 | 31 | // A Symbol is a canonicalized string. |
coleenp@2497 | 32 | // All Symbols reside in global SymbolTable and are reference counted. |
duke@435 | 33 | |
coleenp@2497 | 34 | // Reference counting |
coleenp@2497 | 35 | // |
coleenp@2497 | 36 | // All Symbols are allocated and added to the SymbolTable. |
coleenp@2497 | 37 | // When a class is unloaded, the reference counts of the Symbol pointers in |
coleenp@4037 | 38 | // the ConstantPool and in InstanceKlass (see release_C_heap_structures) are |
coleenp@2497 | 39 | // decremented. When the reference count for a Symbol goes to 0, the garbage |
coleenp@2497 | 40 | // collector can free the Symbol and remove it from the SymbolTable. |
coleenp@2497 | 41 | // |
coleenp@2497 | 42 | // 0) Symbols need to be reference counted when a pointer to the Symbol is |
coleenp@2497 | 43 | // saved in persistent storage. This does not include the pointer |
coleenp@2497 | 44 | // in the SymbolTable bucket (the _literal field in HashtableEntry) |
coleenp@2497 | 45 | // that points to the Symbol. All other stores of a Symbol* |
coleenp@2497 | 46 | // to a field of a persistent variable (e.g., the _name filed in |
coleenp@2497 | 47 | // FieldAccessInfo or _ptr in a CPSlot) is reference counted. |
coleenp@2497 | 48 | // |
coleenp@2497 | 49 | // 1) The lookup of a "name" in the SymbolTable either creates a Symbol F for |
coleenp@2497 | 50 | // "name" and returns a pointer to F or finds a pre-existing Symbol F for |
coleenp@2497 | 51 | // "name" and returns a pointer to it. In both cases the reference count for F |
coleenp@2497 | 52 | // is incremented under the assumption that a pointer to F will be created from |
coleenp@2497 | 53 | // the return value. Thus the increment of the reference count is on the lookup |
coleenp@2497 | 54 | // and not on the assignment to the new Symbol*. That is |
coleenp@2497 | 55 | // Symbol* G = lookup() |
coleenp@2497 | 56 | // ^ increment on lookup() |
coleenp@2497 | 57 | // and not |
coleenp@2497 | 58 | // Symbol* G = lookup() |
coleenp@2497 | 59 | // ^ increment on assignmnet |
coleenp@2497 | 60 | // The reference count must be decremented manually when the copy of the |
coleenp@2497 | 61 | // pointer G is destroyed. |
coleenp@2497 | 62 | // |
coleenp@2497 | 63 | // 2) For a local Symbol* A that is a copy of an existing Symbol* B, the |
coleenp@2497 | 64 | // reference counting is elided when the scope of B is greater than the scope |
coleenp@2497 | 65 | // of A. For example, in the code fragment |
coleenp@2497 | 66 | // below "klass" is passed as a parameter to the method. Symbol* "kn" |
coleenp@2497 | 67 | // is a copy of the name in "klass". |
coleenp@2497 | 68 | // |
coleenp@2497 | 69 | // Symbol* kn = klass->name(); |
coleenp@2497 | 70 | // unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); |
coleenp@2497 | 71 | // |
coleenp@2497 | 72 | // The scope of "klass" is greater than the scope of "kn" so the reference |
coleenp@2497 | 73 | // counting for "kn" is elided. |
coleenp@2497 | 74 | // |
coleenp@2497 | 75 | // Symbol* copied from ConstantPool entries are good candidates for reference |
coleenp@2497 | 76 | // counting elision. The ConstantPool entries for a class C exist until C is |
coleenp@2497 | 77 | // unloaded. If a Symbol* is copied out of the ConstantPool into Symbol* X, |
coleenp@2497 | 78 | // the Symbol* in the ConstantPool will in general out live X so the reference |
coleenp@2497 | 79 | // counting on X can be elided. |
coleenp@2497 | 80 | // |
coleenp@2497 | 81 | // For cases where the scope of A is not greater than the scope of B, |
coleenp@2497 | 82 | // the reference counting is explicitly done. See ciSymbol, |
coleenp@2497 | 83 | // ResolutionErrorEntry and ClassVerifier for examples. |
coleenp@2497 | 84 | // |
coleenp@2497 | 85 | // 3) When a Symbol K is created for temporary use, generally for substrings of |
coleenp@2497 | 86 | // an existing symbol or to create a new symbol, assign it to a |
coleenp@2497 | 87 | // TempNewSymbol. The SymbolTable methods new_symbol(), lookup() |
coleenp@2497 | 88 | // and probe() all potentially return a pointer to a new Symbol. |
coleenp@2497 | 89 | // The allocation (or lookup) of K increments the reference count for K |
coleenp@2497 | 90 | // and the destructor decrements the reference count. |
coleenp@2497 | 91 | // |
coleenp@2497 | 92 | // Another example of TempNewSymbol usage is parsed_name used in |
coleenp@2497 | 93 | // ClassFileParser::parseClassFile() where parsed_name is used in the cleanup |
coleenp@2497 | 94 | // after a failed attempt to load a class. Here parsed_name is a |
coleenp@2497 | 95 | // TempNewSymbol (passed in as a parameter) so the reference count on its symbol |
coleenp@2497 | 96 | // will be decremented when it goes out of scope. |
coleenp@2497 | 97 | |
coleenp@4037 | 98 | |
coleenp@4037 | 99 | // This cannot be inherited from ResourceObj because it cannot have a vtable. |
coleenp@4037 | 100 | // Since sometimes this is allocated from Metadata, pick a base allocation |
coleenp@4037 | 101 | // type without virtual functions. |
coleenp@4037 | 102 | class ClassLoaderData; |
coleenp@4037 | 103 | |
coleenp@4037 | 104 | class Symbol : public MetaspaceObj { |
duke@435 | 105 | friend class VMStructs; |
coleenp@2497 | 106 | friend class SymbolTable; |
coleenp@2497 | 107 | friend class MoveSymbols; |
duke@435 | 108 | private: |
coleenp@2497 | 109 | volatile int _refcount; |
coleenp@2497 | 110 | int _identity_hash; |
duke@435 | 111 | unsigned short _length; // number of UTF8 characters in the symbol |
duke@435 | 112 | jbyte _body[1]; |
duke@435 | 113 | |
duke@435 | 114 | enum { |
duke@435 | 115 | // max_symbol_length is constrained by type of _length |
duke@435 | 116 | max_symbol_length = (1 << 16) -1 |
duke@435 | 117 | }; |
coleenp@2497 | 118 | |
coleenp@4037 | 119 | static int size(int length) { |
coleenp@4037 | 120 | size_t sz = heap_word_size(sizeof(Symbol) + (length > 0 ? length - 1 : 0)); |
coleenp@4037 | 121 | return align_object_size(sz); |
coleenp@2497 | 122 | } |
coleenp@2497 | 123 | |
coleenp@2497 | 124 | void byte_at_put(int index, int value) { |
coleenp@2497 | 125 | assert(index >=0 && index < _length, "symbol index overflow"); |
coleenp@2497 | 126 | _body[index] = value; |
coleenp@2497 | 127 | } |
coleenp@2497 | 128 | |
coleenp@3682 | 129 | Symbol(const u1* name, int length, int refcount); |
coleenp@3682 | 130 | void* operator new(size_t size, int len, TRAPS); |
coleenp@3682 | 131 | void* operator new(size_t size, int len, Arena* arena, TRAPS); |
coleenp@4037 | 132 | void* operator new(size_t size, int len, ClassLoaderData* loader_data, TRAPS); |
coleenp@4037 | 133 | |
coleenp@4037 | 134 | void operator delete(void* p); |
coleenp@2497 | 135 | |
duke@435 | 136 | public: |
coleenp@2497 | 137 | // Low-level access (used with care, since not GC-safe) |
coleenp@2497 | 138 | const jbyte* base() const { return &_body[0]; } |
duke@435 | 139 | |
coleenp@4037 | 140 | int size() { return size(utf8_length()); } |
duke@435 | 141 | |
duke@435 | 142 | // Returns the largest size symbol we can safely hold. |
coleenp@3682 | 143 | static int max_length() { return max_symbol_length; } |
duke@435 | 144 | |
coleenp@3682 | 145 | int identity_hash() { return _identity_hash; } |
duke@435 | 146 | |
coleenp@4037 | 147 | // For symbol table alternate hashing |
coleenp@4037 | 148 | unsigned int new_hash(jint seed); |
coleenp@4037 | 149 | |
coleenp@2497 | 150 | // Reference counting. See comments above this class for when to use. |
coleenp@3682 | 151 | int refcount() const { return _refcount; } |
simonis@4675 | 152 | void increment_refcount(); |
simonis@4675 | 153 | void decrement_refcount(); |
duke@435 | 154 | |
duke@435 | 155 | int byte_at(int index) const { |
duke@435 | 156 | assert(index >=0 && index < _length, "symbol index overflow"); |
coleenp@2497 | 157 | return base()[index]; |
duke@435 | 158 | } |
duke@435 | 159 | |
coleenp@2497 | 160 | const jbyte* bytes() const { return base(); } |
duke@435 | 161 | |
duke@435 | 162 | int utf8_length() const { return _length; } |
duke@435 | 163 | |
twisti@1573 | 164 | // Compares the symbol with a string. |
duke@435 | 165 | bool equals(const char* str, int len) const; |
twisti@1573 | 166 | bool equals(const char* str) const { return equals(str, (int) strlen(str)); } |
twisti@1573 | 167 | |
twisti@1573 | 168 | // Tests if the symbol starts with the given prefix. |
twisti@1573 | 169 | bool starts_with(const char* prefix, int len) const; |
twisti@1573 | 170 | bool starts_with(const char* prefix) const { |
twisti@1573 | 171 | return starts_with(prefix, (int) strlen(prefix)); |
twisti@1573 | 172 | } |
twisti@1573 | 173 | |
twisti@1573 | 174 | // Tests if the symbol starts with the given prefix. |
twisti@1573 | 175 | int index_of_at(int i, const char* str, int len) const; |
twisti@1573 | 176 | int index_of_at(int i, const char* str) const { |
twisti@1573 | 177 | return index_of_at(i, str, (int) strlen(str)); |
twisti@1573 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg |
duke@435 | 181 | // note that the ordering is not alfabetical |
coleenp@2497 | 182 | inline int fast_compare(Symbol* other) const; |
duke@435 | 183 | |
duke@435 | 184 | // Returns receiver converted to null-terminated UTF-8 string; string is |
duke@435 | 185 | // allocated in resource area, or in the char buffer provided by caller. |
duke@435 | 186 | char* as_C_string() const; |
duke@435 | 187 | char* as_C_string(char* buf, int size) const; |
duke@435 | 188 | // Use buf if needed buffer length is <= size. |
duke@435 | 189 | char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const; |
duke@435 | 190 | |
minqi@4267 | 191 | // Returns an escaped form of a Java string. |
minqi@4267 | 192 | char* as_quoted_ascii() const; |
duke@435 | 193 | |
duke@435 | 194 | // Returns a null terminated utf8 string in a resource array |
duke@435 | 195 | char* as_utf8() const { return as_C_string(); } |
duke@435 | 196 | char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const { |
duke@435 | 197 | return as_C_string_flexible_buffer(t, buf, size); |
duke@435 | 198 | } |
duke@435 | 199 | |
duke@435 | 200 | jchar* as_unicode(int& length) const; |
duke@435 | 201 | |
duke@435 | 202 | // Treating this symbol as a class name, returns the Java name for the class. |
duke@435 | 203 | // String is allocated in resource area if buffer is not provided. |
duke@435 | 204 | // See Klass::external_name() |
duke@435 | 205 | const char* as_klass_external_name() const; |
duke@435 | 206 | const char* as_klass_external_name(char* buf, int size) const; |
duke@435 | 207 | |
coleenp@2497 | 208 | // Printing |
coleenp@2497 | 209 | void print_symbol_on(outputStream* st = NULL) const; |
coleenp@2497 | 210 | void print_on(outputStream* st) const; // First level print |
coleenp@2497 | 211 | void print_value_on(outputStream* st) const; // Second level print. |
duke@435 | 212 | |
coleenp@2497 | 213 | // printing on default output stream |
coleenp@2497 | 214 | void print() { print_on(tty); } |
coleenp@2497 | 215 | void print_value() { print_value_on(tty); } |
coleenp@2497 | 216 | |
coleenp@2497 | 217 | #ifndef PRODUCT |
coleenp@2497 | 218 | // Empty constructor to create a dummy symbol object on stack |
coleenp@2497 | 219 | // only for getting its vtable pointer. |
coleenp@2497 | 220 | Symbol() { } |
coleenp@2497 | 221 | |
coleenp@2497 | 222 | static int _total_count; |
coleenp@2497 | 223 | #endif |
duke@435 | 224 | }; |
duke@435 | 225 | |
duke@435 | 226 | // Note: this comparison is used for vtable sorting only; it doesn't matter |
duke@435 | 227 | // what order it defines, as long as it is a total, time-invariant order |
coleenp@2497 | 228 | // Since Symbol*s are in C_HEAP, their relative order in memory never changes, |
duke@435 | 229 | // so use address comparison for speed |
coleenp@2497 | 230 | int Symbol::fast_compare(Symbol* other) const { |
duke@435 | 231 | return (((uintptr_t)this < (uintptr_t)other) ? -1 |
duke@435 | 232 | : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1); |
duke@435 | 233 | } |
coleenp@2497 | 234 | #endif // SHARE_VM_OOPS_SYMBOL_HPP |