annotate src/share/vm/oops/symbolOop.hpp @ 2002:ac637b7220d1

6985015: C1 needs to support compressed oops Summary: This change implements compressed oops for C1 for x64 and sparc. The changes are mostly on the codegen level, with a few exceptions when we do access things outside of the heap that are uncompressed from the IR. Compressed oops are now also enabled with tiered. Reviewed-by: twisti, kvn, never, phh
author iveresov
date Tue, 30 Nov 2010 23:23:40 -0800
parents f95d63e2154a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_OOPS_SYMBOLOOP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_OOPS_SYMBOLOOP_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "oops/typeArrayOop.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/utf8.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30
0
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // A symbolOop is a canonicalized string.
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // All symbolOops reside in global symbolTable.
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // See oopFactory::new_symbol for how to allocate a symbolOop
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 class symbolOopDesc : public oopDesc {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 unsigned short _length; // number of UTF8 characters in the symbol
a61af66fc99e Initial load
duke
parents:
diff changeset
39 jbyte _body[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // max_symbol_length is constrained by type of _length
a61af66fc99e Initial load
duke
parents:
diff changeset
43 max_symbol_length = (1 << 16) -1
a61af66fc99e Initial load
duke
parents:
diff changeset
44 };
a61af66fc99e Initial load
duke
parents:
diff changeset
45 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // Low-level access (used with care, since not GC-safe)
a61af66fc99e Initial load
duke
parents:
diff changeset
48 jbyte* base() { return &_body[0]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Returns the largest size symbol we can safely hold.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 static int max_length() {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return max_symbol_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 static int object_size(int length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 int size = header_size() + (sizeof(unsigned short) + length + HeapWordSize - 1) / HeapWordSize;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return align_object_size(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 int object_size() { return object_size(utf8_length()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 int byte_at(int index) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 assert(index >=0 && index < _length, "symbol index overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return ((symbolOopDesc*)this)->base()[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 void byte_at_put(int index, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(index >=0 && index < _length, "symbol index overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 ((symbolOopDesc*)this)->base()[index] = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 jbyte* bytes() { return base(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int utf8_length() const { return _length; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 void set_utf8_length(int len) { _length = len; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
79 // Compares the symbol with a string.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
80 bool equals(const char* str, int len) const;
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
81 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
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 bool starts_with(const char* prefix, int len) const;
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
85 bool starts_with(const char* prefix) const {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
86 return starts_with(prefix, (int) strlen(prefix));
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
87 }
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
88
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
89 // Tests if the symbol starts with the given prefix.
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
90 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
91 int index_of_at(int i, const char* str) const {
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
92 return index_of_at(i, str, (int) strlen(str));
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 0
diff changeset
93 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // note that the ordering is not alfabetical
a61af66fc99e Initial load
duke
parents:
diff changeset
97 inline int fast_compare(symbolOop other) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Returns receiver converted to null-terminated UTF-8 string; string is
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // allocated in resource area, or in the char buffer provided by caller.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 char* as_C_string() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 char* as_C_string(char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // Use buf if needed buffer length is <= size.
a61af66fc99e Initial load
duke
parents:
diff changeset
104 char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // Returns a null terminated utf8 string in a resource array
a61af66fc99e Initial load
duke
parents:
diff changeset
108 char* as_utf8() const { return as_C_string(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return as_C_string_flexible_buffer(t, buf, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 jchar* as_unicode(int& length) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // Treating this symbol as a class name, returns the Java name for the class.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // String is allocated in resource area if buffer is not provided.
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // See Klass::external_name()
a61af66fc99e Initial load
duke
parents:
diff changeset
118 const char* as_klass_external_name() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 const char* as_klass_external_name(char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 bool object_is_parsable() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return (utf8_length() > 0 || (oop)this == Universe::emptySymbol());
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Printing
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void print_symbol_on(outputStream* st = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 };
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 // Note: this comparison is used for vtable sorting only; it doesn't matter
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // what order it defines, as long as it is a total, time-invariant order
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // Since symbolOops are in permSpace, their relative order in memory never changes,
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // so use address comparison for speed
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int symbolOopDesc::fast_compare(symbolOop other) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return (((uintptr_t)this < (uintptr_t)other) ? -1
a61af66fc99e Initial load
duke
parents:
diff changeset
136 : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
138
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
139 #endif // SHARE_VM_OOPS_SYMBOLOOP_HPP