Tue, 05 Jan 2010 15:21:25 +0100
6893268: additional dynamic language related optimizations in C2
Summary: C2 needs some additional optimizations to be able to handle MethodHandle invokes and invokedynamic instructions at the best performance.
Reviewed-by: kvn, never
duke@435 | 1 | /* |
twisti@1573 | 2 | * Copyright 1997-2009 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // A symbolOop is a canonicalized string. |
duke@435 | 26 | // All symbolOops reside in global symbolTable. |
duke@435 | 27 | // See oopFactory::new_symbol for how to allocate a symbolOop |
duke@435 | 28 | |
duke@435 | 29 | class symbolOopDesc : public oopDesc { |
duke@435 | 30 | friend class VMStructs; |
duke@435 | 31 | private: |
duke@435 | 32 | unsigned short _length; // number of UTF8 characters in the symbol |
duke@435 | 33 | jbyte _body[1]; |
duke@435 | 34 | |
duke@435 | 35 | enum { |
duke@435 | 36 | // max_symbol_length is constrained by type of _length |
duke@435 | 37 | max_symbol_length = (1 << 16) -1 |
duke@435 | 38 | }; |
duke@435 | 39 | public: |
duke@435 | 40 | |
duke@435 | 41 | // Low-level access (used with care, since not GC-safe) |
duke@435 | 42 | jbyte* base() { return &_body[0]; } |
duke@435 | 43 | |
duke@435 | 44 | |
duke@435 | 45 | // Returns the largest size symbol we can safely hold. |
duke@435 | 46 | static int max_length() { |
duke@435 | 47 | return max_symbol_length; |
duke@435 | 48 | } |
duke@435 | 49 | |
duke@435 | 50 | static int object_size(int length) { |
duke@435 | 51 | int size = header_size() + (sizeof(unsigned short) + length + HeapWordSize - 1) / HeapWordSize; |
duke@435 | 52 | return align_object_size(size); |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | int object_size() { return object_size(utf8_length()); } |
duke@435 | 56 | |
duke@435 | 57 | int byte_at(int index) const { |
duke@435 | 58 | assert(index >=0 && index < _length, "symbol index overflow"); |
duke@435 | 59 | return ((symbolOopDesc*)this)->base()[index]; |
duke@435 | 60 | } |
duke@435 | 61 | |
duke@435 | 62 | void byte_at_put(int index, int value) { |
duke@435 | 63 | assert(index >=0 && index < _length, "symbol index overflow"); |
duke@435 | 64 | ((symbolOopDesc*)this)->base()[index] = value; |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | jbyte* bytes() { return base(); } |
duke@435 | 68 | |
duke@435 | 69 | int utf8_length() const { return _length; } |
duke@435 | 70 | |
duke@435 | 71 | void set_utf8_length(int len) { _length = len; } |
duke@435 | 72 | |
twisti@1573 | 73 | // Compares the symbol with a string. |
duke@435 | 74 | bool equals(const char* str, int len) const; |
twisti@1573 | 75 | bool equals(const char* str) const { return equals(str, (int) strlen(str)); } |
twisti@1573 | 76 | |
twisti@1573 | 77 | // Tests if the symbol starts with the given prefix. |
twisti@1573 | 78 | bool starts_with(const char* prefix, int len) const; |
twisti@1573 | 79 | bool starts_with(const char* prefix) const { |
twisti@1573 | 80 | return starts_with(prefix, (int) strlen(prefix)); |
twisti@1573 | 81 | } |
twisti@1573 | 82 | |
twisti@1573 | 83 | // Tests if the symbol starts with the given prefix. |
twisti@1573 | 84 | int index_of_at(int i, const char* str, int len) const; |
twisti@1573 | 85 | int index_of_at(int i, const char* str) const { |
twisti@1573 | 86 | return index_of_at(i, str, (int) strlen(str)); |
twisti@1573 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg |
duke@435 | 90 | // note that the ordering is not alfabetical |
duke@435 | 91 | inline int fast_compare(symbolOop other) const; |
duke@435 | 92 | |
duke@435 | 93 | // Returns receiver converted to null-terminated UTF-8 string; string is |
duke@435 | 94 | // allocated in resource area, or in the char buffer provided by caller. |
duke@435 | 95 | char* as_C_string() const; |
duke@435 | 96 | char* as_C_string(char* buf, int size) const; |
duke@435 | 97 | // Use buf if needed buffer length is <= size. |
duke@435 | 98 | char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const; |
duke@435 | 99 | |
duke@435 | 100 | |
duke@435 | 101 | // Returns a null terminated utf8 string in a resource array |
duke@435 | 102 | char* as_utf8() const { return as_C_string(); } |
duke@435 | 103 | char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const { |
duke@435 | 104 | return as_C_string_flexible_buffer(t, buf, size); |
duke@435 | 105 | } |
duke@435 | 106 | |
duke@435 | 107 | jchar* as_unicode(int& length) const; |
duke@435 | 108 | |
duke@435 | 109 | // Treating this symbol as a class name, returns the Java name for the class. |
duke@435 | 110 | // String is allocated in resource area if buffer is not provided. |
duke@435 | 111 | // See Klass::external_name() |
duke@435 | 112 | const char* as_klass_external_name() const; |
duke@435 | 113 | const char* as_klass_external_name(char* buf, int size) const; |
duke@435 | 114 | |
duke@435 | 115 | bool object_is_parsable() const { |
duke@435 | 116 | return (utf8_length() > 0 || (oop)this == Universe::emptySymbol()); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | // Printing |
duke@435 | 120 | void print_symbol_on(outputStream* st = NULL); |
duke@435 | 121 | }; |
duke@435 | 122 | |
duke@435 | 123 | |
duke@435 | 124 | // Note: this comparison is used for vtable sorting only; it doesn't matter |
duke@435 | 125 | // what order it defines, as long as it is a total, time-invariant order |
duke@435 | 126 | // Since symbolOops are in permSpace, their relative order in memory never changes, |
duke@435 | 127 | // so use address comparison for speed |
duke@435 | 128 | int symbolOopDesc::fast_compare(symbolOop other) const { |
duke@435 | 129 | return (((uintptr_t)this < (uintptr_t)other) ? -1 |
duke@435 | 130 | : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1); |
duke@435 | 131 | } |