annotate src/share/vm/oops/symbolOop.hpp @ 1375:e0a1a502e402 jdk7-b91

Added tag jdk7-b90 for changeset 605c9707a766
author mikejwre
date Thu, 22 Apr 2010 16:54:23 -0700
parents dd57230ba8fe
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 // A symbolOop is a canonicalized string.
a61af66fc99e Initial load
duke
parents:
diff changeset
26 // All symbolOops reside in global symbolTable.
a61af66fc99e Initial load
duke
parents:
diff changeset
27 // See oopFactory::new_symbol for how to allocate a symbolOop
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 class symbolOopDesc : public oopDesc {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
32 unsigned short _length; // number of UTF8 characters in the symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
33 jbyte _body[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // max_symbol_length is constrained by type of _length
a61af66fc99e Initial load
duke
parents:
diff changeset
37 max_symbol_length = (1 << 16) -1
a61af66fc99e Initial load
duke
parents:
diff changeset
38 };
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Low-level access (used with care, since not GC-safe)
a61af66fc99e Initial load
duke
parents:
diff changeset
42 jbyte* base() { return &_body[0]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // Returns the largest size symbol we can safely hold.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static int max_length() {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 return max_symbol_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 static int object_size(int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 int size = header_size() + (sizeof(unsigned short) + length + HeapWordSize - 1) / HeapWordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return align_object_size(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 int object_size() { return object_size(utf8_length()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int byte_at(int index) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 assert(index >=0 && index < _length, "symbol index overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return ((symbolOopDesc*)this)->base()[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 void byte_at_put(int index, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 assert(index >=0 && index < _length, "symbol index overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 ((symbolOopDesc*)this)->base()[index] = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 jbyte* bytes() { return base(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int utf8_length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void set_utf8_length(int len) { _length = len; }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
73 // Compares the symbol with a string.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 bool equals(const char* str, int len) const;
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
75 bool equals(const char* str) const { return equals(str, (int) strlen(str)); }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
76
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
77 // Tests if the symbol starts with the given prefix.
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
78 bool starts_with(const char* prefix, int len) const;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
79 bool starts_with(const char* prefix) const {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
80 return starts_with(prefix, (int) strlen(prefix));
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
81 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
82
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
83 // Tests if the symbol starts with the given prefix.
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
84 int index_of_at(int i, const char* str, int len) const;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
85 int index_of_at(int i, const char* str) const {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
86 return index_of_at(i, str, (int) strlen(str));
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
87 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // note that the ordering is not alfabetical
a61af66fc99e Initial load
duke
parents:
diff changeset
91 inline int fast_compare(symbolOop other) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Returns receiver converted to null-terminated UTF-8 string; string is
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // allocated in resource area, or in the char buffer provided by caller.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 char* as_C_string() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 char* as_C_string(char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Use buf if needed buffer length is <= size.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Returns a null terminated utf8 string in a resource array
a61af66fc99e Initial load
duke
parents:
diff changeset
102 char* as_utf8() const { return as_C_string(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return as_C_string_flexible_buffer(t, buf, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 jchar* as_unicode(int& length) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // Treating this symbol as a class name, returns the Java name for the class.
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // String is allocated in resource area if buffer is not provided.
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // See Klass::external_name()
a61af66fc99e Initial load
duke
parents:
diff changeset
112 const char* as_klass_external_name() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 const char* as_klass_external_name(char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 bool object_is_parsable() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return (utf8_length() > 0 || (oop)this == Universe::emptySymbol());
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Printing
a61af66fc99e Initial load
duke
parents:
diff changeset
120 void print_symbol_on(outputStream* st = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 };
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Note: this comparison is used for vtable sorting only; it doesn't matter
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // what order it defines, as long as it is a total, time-invariant order
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Since symbolOops are in permSpace, their relative order in memory never changes,
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // so use address comparison for speed
a61af66fc99e Initial load
duke
parents:
diff changeset
128 int symbolOopDesc::fast_compare(symbolOop other) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 return (((uintptr_t)this < (uintptr_t)other) ? -1
a61af66fc99e Initial load
duke
parents:
diff changeset
130 : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }