annotate src/share/vm/oops/symbolOop.hpp @ 974:26b774d693aa

Merge
author acorn
date Wed, 16 Sep 2009 09:10:57 -0400
parents a61af66fc99e
children dd57230ba8fe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
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
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // Compares the symbol with a string
a61af66fc99e Initial load
duke
parents:
diff changeset
74 bool equals(const char* str, int len) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // Three-way compare for sorting; returns -1/0/1 if receiver is </==/> than arg
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // note that the ordering is not alfabetical
a61af66fc99e Initial load
duke
parents:
diff changeset
78 inline int fast_compare(symbolOop other) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Returns receiver converted to null-terminated UTF-8 string; string is
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // allocated in resource area, or in the char buffer provided by caller.
a61af66fc99e Initial load
duke
parents:
diff changeset
82 char* as_C_string() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 char* as_C_string(char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // Use buf if needed buffer length is <= size.
a61af66fc99e Initial load
duke
parents:
diff changeset
85 char* as_C_string_flexible_buffer(Thread* t, char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Returns a null terminated utf8 string in a resource array
a61af66fc99e Initial load
duke
parents:
diff changeset
89 char* as_utf8() const { return as_C_string(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 char* as_utf8_flexible_buffer(Thread* t, char* buf, int size) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return as_C_string_flexible_buffer(t, buf, size);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 jchar* as_unicode(int& length) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Treating this symbol as a class name, returns the Java name for the class.
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // String is allocated in resource area if buffer is not provided.
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // See Klass::external_name()
a61af66fc99e Initial load
duke
parents:
diff changeset
99 const char* as_klass_external_name() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 const char* as_klass_external_name(char* buf, int size) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 bool object_is_parsable() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return (utf8_length() > 0 || (oop)this == Universe::emptySymbol());
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Printing
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void print_symbol_on(outputStream* st = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 };
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // Note: this comparison is used for vtable sorting only; it doesn't matter
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // what order it defines, as long as it is a total, time-invariant order
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // Since symbolOops are in permSpace, their relative order in memory never changes,
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // so use address comparison for speed
a61af66fc99e Initial load
duke
parents:
diff changeset
115 int symbolOopDesc::fast_compare(symbolOop other) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return (((uintptr_t)this < (uintptr_t)other) ? -1
a61af66fc99e Initial load
duke
parents:
diff changeset
117 : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }