1 /*
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // A symbolOop is a canonicalized string.
26 // All symbolOops reside in global symbolTable.
27 // See oopFactory::new_symbol for how to allocate a symbolOop
28
29 class symbolOopDesc : public oopDesc {
30 friend class VMStructs;
31 private:
32 unsigned short _length; // number of UTF8 characters in the symbol
33 jbyte _body[1];
34
35 enum {
36 // max_symbol_length is constrained by type of _length
37 max_symbol_length = (1 << 16) -1
38 };
39 public:
40
41 // Low-level access (used with care, since not GC-safe)
42 jbyte* base() { return &_body[0]; }
43
44
112 const char* as_klass_external_name() const;
113 const char* as_klass_external_name(char* buf, int size) const;
114
115 bool object_is_parsable() const {
116 return (utf8_length() > 0 || (oop)this == Universe::emptySymbol());
117 }
118
119 // Printing
120 void print_symbol_on(outputStream* st = NULL);
121 };
122
123
124 // Note: this comparison is used for vtable sorting only; it doesn't matter
125 // what order it defines, as long as it is a total, time-invariant order
126 // Since symbolOops are in permSpace, their relative order in memory never changes,
127 // so use address comparison for speed
128 int symbolOopDesc::fast_compare(symbolOop other) const {
129 return (((uintptr_t)this < (uintptr_t)other) ? -1
130 : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
131 }
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_SYMBOLOOP_HPP
26 #define SHARE_VM_OOPS_SYMBOLOOP_HPP
27
28 #include "oops/typeArrayOop.hpp"
29 #include "utilities/utf8.hpp"
30
31 // A symbolOop is a canonicalized string.
32 // All symbolOops reside in global symbolTable.
33 // See oopFactory::new_symbol for how to allocate a symbolOop
34
35 class symbolOopDesc : public oopDesc {
36 friend class VMStructs;
37 private:
38 unsigned short _length; // number of UTF8 characters in the symbol
39 jbyte _body[1];
40
41 enum {
42 // max_symbol_length is constrained by type of _length
43 max_symbol_length = (1 << 16) -1
44 };
45 public:
46
47 // Low-level access (used with care, since not GC-safe)
48 jbyte* base() { return &_body[0]; }
49
50
118 const char* as_klass_external_name() const;
119 const char* as_klass_external_name(char* buf, int size) const;
120
121 bool object_is_parsable() const {
122 return (utf8_length() > 0 || (oop)this == Universe::emptySymbol());
123 }
124
125 // Printing
126 void print_symbol_on(outputStream* st = NULL);
127 };
128
129
130 // Note: this comparison is used for vtable sorting only; it doesn't matter
131 // what order it defines, as long as it is a total, time-invariant order
132 // Since symbolOops are in permSpace, their relative order in memory never changes,
133 // so use address comparison for speed
134 int symbolOopDesc::fast_compare(symbolOop other) const {
135 return (((uintptr_t)this < (uintptr_t)other) ? -1
136 : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
137 }
138
139 #endif // SHARE_VM_OOPS_SYMBOLOOP_HPP
|