Mercurial > hg > truffle
annotate src/share/vm/oops/symbolOop.cpp @ 1604:b918d354830a
6960865: ldc of unloaded class throws an assert in ciTypeFlow
Summary: Support java_mirror for unloaded klasses, arrays as well as instances. Simplify ciTypeFlow by removing unused path.
Reviewed-by: kvn
author | jrose |
---|---|
date | Sat, 12 Jun 2010 22:53:43 -0700 |
parents | c18cbe5936b8 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
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 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_symbolOop.cpp.incl" | |
27 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
28 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
29 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
30 // symbolOopDesc::equals |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
31 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
32 // Compares the symbol with a string of the given length. |
0 | 33 bool symbolOopDesc::equals(const char* str, int len) const { |
34 int l = utf8_length(); | |
35 if (l != len) return false; | |
36 while (l-- > 0) { | |
37 if (str[l] != (char) byte_at(l)) | |
38 return false; | |
39 } | |
40 assert(l == -1, "we should be at the beginning"); | |
41 return true; | |
42 } | |
43 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
44 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
45 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
46 // symbolOopDesc::starts_with |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
47 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
48 // Tests if the symbol starts with the specified prefix of the given |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
49 // length. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
50 bool symbolOopDesc::starts_with(const char* prefix, int len) const { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
51 if (len > utf8_length()) return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
52 while (len-- > 0) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
53 if (prefix[len] != (char) byte_at(len)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
54 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
55 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
56 assert(len == -1, "we should be at the beginning"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
57 return true; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
58 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
59 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
60 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
61 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
62 // symbolOopDesc::index_of |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
63 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
64 // Finds if the given string is a substring of this symbol's utf8 bytes. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
65 // Return -1 on failure. Otherwise return the first index where str occurs. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
66 int symbolOopDesc::index_of_at(int i, const char* str, int len) const { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
67 assert(i >= 0 && i <= utf8_length(), "oob"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
68 if (len <= 0) return 0; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
69 char first_char = str[0]; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
70 address bytes = (address) ((symbolOopDesc*)this)->base(); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
71 address limit = bytes + utf8_length() - len; // inclusive limit |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
72 address scan = bytes + i; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
73 if (scan > limit) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
74 return -1; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
75 for (;;) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
76 scan = (address) memchr(scan, first_char, (limit + 1 - scan)); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
77 if (scan == NULL) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
78 return -1; // not found |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
79 assert(scan >= bytes+i && scan <= limit, "scan oob"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
80 if (memcmp(scan, str, len) == 0) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
81 return (int)(scan - bytes); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
82 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
83 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
84 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
85 |
0 | 86 char* symbolOopDesc::as_C_string(char* buf, int size) const { |
87 if (size > 0) { | |
88 int len = MIN2(size - 1, utf8_length()); | |
89 for (int i = 0; i < len; i++) { | |
90 buf[i] = byte_at(i); | |
91 } | |
92 buf[len] = '\0'; | |
93 } | |
94 return buf; | |
95 } | |
96 | |
97 char* symbolOopDesc::as_C_string() const { | |
98 int len = utf8_length(); | |
99 char* str = NEW_RESOURCE_ARRAY(char, len + 1); | |
100 return as_C_string(str, len + 1); | |
101 } | |
102 | |
103 char* symbolOopDesc::as_C_string_flexible_buffer(Thread* t, | |
104 char* buf, int size) const { | |
105 char* str; | |
106 int len = utf8_length(); | |
107 int buf_len = len + 1; | |
108 if (size < buf_len) { | |
109 str = NEW_RESOURCE_ARRAY(char, buf_len); | |
110 } else { | |
111 str = buf; | |
112 } | |
113 return as_C_string(str, buf_len); | |
114 } | |
115 | |
116 void symbolOopDesc::print_symbol_on(outputStream* st) { | |
117 st = st ? st : tty; | |
222 | 118 int length = UTF8::unicode_length((const char*)bytes(), utf8_length()); |
119 const char *ptr = (const char *)bytes(); | |
120 jchar value; | |
121 for (int index = 0; index < length; index++) { | |
122 ptr = UTF8::next(ptr, &value); | |
123 if (value >= 32 && value < 127 || value == '\'' || value == '\\') { | |
124 st->put(value); | |
125 } else { | |
126 st->print("\\u%04x", value); | |
127 } | |
128 } | |
0 | 129 } |
130 | |
131 jchar* symbolOopDesc::as_unicode(int& length) const { | |
132 symbolOopDesc* this_ptr = (symbolOopDesc*)this; | |
133 length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); | |
134 jchar* result = NEW_RESOURCE_ARRAY(jchar, length); | |
135 if (length > 0) { | |
136 UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); | |
137 } | |
138 return result; | |
139 } | |
140 | |
141 const char* symbolOopDesc::as_klass_external_name(char* buf, int size) const { | |
142 if (size > 0) { | |
143 char* str = as_C_string(buf, size); | |
144 int length = (int)strlen(str); | |
145 // Turn all '/'s into '.'s (also for array klasses) | |
146 for (int index = 0; index < length; index++) { | |
147 if (str[index] == '/') { | |
148 str[index] = '.'; | |
149 } | |
150 } | |
151 return str; | |
152 } else { | |
153 return buf; | |
154 } | |
155 } | |
156 | |
157 const char* symbolOopDesc::as_klass_external_name() const { | |
158 char* str = as_C_string(); | |
159 int length = (int)strlen(str); | |
160 // Turn all '/'s into '.'s (also for array klasses) | |
161 for (int index = 0; index < length; index++) { | |
162 if (str[index] == '/') { | |
163 str[index] = '.'; | |
164 } | |
165 } | |
166 return str; | |
167 } |