Mercurial > hg > truffle
annotate src/share/vm/oops/symbolOop.cpp @ 2066:02895c6a2f82
7007769: VM crashes with SIGBUS writing PerfData if tmp space is full
Summary: Fill perfdata file with zeros to verify available disk space
Reviewed-by: coleenp, kamg
author | bobv |
---|---|
date | Mon, 20 Dec 2010 14:30:24 -0500 |
parents | f95d63e2154a |
children |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 1997, 2010, 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 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "oops/oop.inline.hpp" | |
27 #include "oops/symbolOop.hpp" | |
0 | 28 |
1138
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 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
31 // symbolOopDesc::equals |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
32 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
33 // Compares the symbol with a string of the given length. |
0 | 34 bool symbolOopDesc::equals(const char* str, int len) const { |
35 int l = utf8_length(); | |
36 if (l != len) return false; | |
37 while (l-- > 0) { | |
38 if (str[l] != (char) byte_at(l)) | |
39 return false; | |
40 } | |
41 assert(l == -1, "we should be at the beginning"); | |
42 return true; | |
43 } | |
44 | |
1138
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 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
47 // symbolOopDesc::starts_with |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
48 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
49 // 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
|
50 // length. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
51 bool symbolOopDesc::starts_with(const char* prefix, int len) const { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
52 if (len > utf8_length()) return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
53 while (len-- > 0) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
54 if (prefix[len] != (char) byte_at(len)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
55 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
56 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
57 assert(len == -1, "we should be at the beginning"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
58 return true; |
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 // ------------------------------------------------------------------ |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
63 // symbolOopDesc::index_of |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
64 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
65 // 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
|
66 // 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
|
67 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
|
68 assert(i >= 0 && i <= utf8_length(), "oob"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
69 if (len <= 0) return 0; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
70 char first_char = str[0]; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
71 address bytes = (address) ((symbolOopDesc*)this)->base(); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
72 address limit = bytes + utf8_length() - len; // inclusive limit |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
73 address scan = bytes + i; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
74 if (scan > limit) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
75 return -1; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
76 for (;;) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
77 scan = (address) memchr(scan, first_char, (limit + 1 - scan)); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
78 if (scan == NULL) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
79 return -1; // not found |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
80 assert(scan >= bytes+i && scan <= limit, "scan oob"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
81 if (memcmp(scan, str, len) == 0) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
82 return (int)(scan - bytes); |
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 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
86 |
0 | 87 char* symbolOopDesc::as_C_string(char* buf, int size) const { |
88 if (size > 0) { | |
89 int len = MIN2(size - 1, utf8_length()); | |
90 for (int i = 0; i < len; i++) { | |
91 buf[i] = byte_at(i); | |
92 } | |
93 buf[len] = '\0'; | |
94 } | |
95 return buf; | |
96 } | |
97 | |
98 char* symbolOopDesc::as_C_string() const { | |
99 int len = utf8_length(); | |
100 char* str = NEW_RESOURCE_ARRAY(char, len + 1); | |
101 return as_C_string(str, len + 1); | |
102 } | |
103 | |
104 char* symbolOopDesc::as_C_string_flexible_buffer(Thread* t, | |
105 char* buf, int size) const { | |
106 char* str; | |
107 int len = utf8_length(); | |
108 int buf_len = len + 1; | |
109 if (size < buf_len) { | |
110 str = NEW_RESOURCE_ARRAY(char, buf_len); | |
111 } else { | |
112 str = buf; | |
113 } | |
114 return as_C_string(str, buf_len); | |
115 } | |
116 | |
117 void symbolOopDesc::print_symbol_on(outputStream* st) { | |
118 st = st ? st : tty; | |
222 | 119 int length = UTF8::unicode_length((const char*)bytes(), utf8_length()); |
120 const char *ptr = (const char *)bytes(); | |
121 jchar value; | |
122 for (int index = 0; index < length; index++) { | |
123 ptr = UTF8::next(ptr, &value); | |
124 if (value >= 32 && value < 127 || value == '\'' || value == '\\') { | |
125 st->put(value); | |
126 } else { | |
127 st->print("\\u%04x", value); | |
128 } | |
129 } | |
0 | 130 } |
131 | |
132 jchar* symbolOopDesc::as_unicode(int& length) const { | |
133 symbolOopDesc* this_ptr = (symbolOopDesc*)this; | |
134 length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); | |
135 jchar* result = NEW_RESOURCE_ARRAY(jchar, length); | |
136 if (length > 0) { | |
137 UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); | |
138 } | |
139 return result; | |
140 } | |
141 | |
142 const char* symbolOopDesc::as_klass_external_name(char* buf, int size) const { | |
143 if (size > 0) { | |
144 char* str = as_C_string(buf, size); | |
145 int length = (int)strlen(str); | |
146 // Turn all '/'s into '.'s (also for array klasses) | |
147 for (int index = 0; index < length; index++) { | |
148 if (str[index] == '/') { | |
149 str[index] = '.'; | |
150 } | |
151 } | |
152 return str; | |
153 } else { | |
154 return buf; | |
155 } | |
156 } | |
157 | |
158 const char* symbolOopDesc::as_klass_external_name() const { | |
159 char* str = as_C_string(); | |
160 int length = (int)strlen(str); | |
161 // Turn all '/'s into '.'s (also for array klasses) | |
162 for (int index = 0; index < length; index++) { | |
163 if (str[index] == '/') { | |
164 str[index] = '.'; | |
165 } | |
166 } | |
167 return str; | |
168 } |