author | trims |
Tue, 05 Apr 2011 14:12:31 -0700 | |
changeset 8921 | 14bfe81f2a9d |
parent 8076 | 96d498ec7ae1 |
child 10008 | d84de97ad847 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8921
14bfe81f2a9d
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
8076
diff
changeset
|
2 |
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "ci/ciInstanceKlass.hpp" |
|
27 |
#include "ci/ciObjArrayKlass.hpp" |
|
28 |
#include "ci/ciObjArrayKlassKlass.hpp" |
|
29 |
#include "ci/ciSymbol.hpp" |
|
30 |
#include "ci/ciUtilities.hpp" |
|
31 |
#include "oops/objArrayKlass.hpp" |
|
1 | 32 |
|
33 |
// ciObjArrayKlass |
|
34 |
// |
|
35 |
// This class represents a klassOop in the HotSpot virtual machine |
|
36 |
// whose Klass part is an objArrayKlass. |
|
37 |
||
38 |
// ------------------------------------------------------------------ |
|
39 |
// ciObjArrayKlass::ciObjArrayKlass |
|
40 |
// |
|
41 |
// Constructor for loaded object array klasses. |
|
42 |
ciObjArrayKlass::ciObjArrayKlass(KlassHandle h_k) : ciArrayKlass(h_k) { |
|
43 |
assert(get_Klass()->oop_is_objArray(), "wrong type"); |
|
44 |
klassOop element_klassOop = get_objArrayKlass()->bottom_klass(); |
|
45 |
_base_element_klass = CURRENT_ENV->get_object(element_klassOop)->as_klass(); |
|
46 |
assert(_base_element_klass->is_instance_klass() || |
|
47 |
_base_element_klass->is_type_array_klass(), "bad base klass"); |
|
48 |
if (dimension() == 1) { |
|
49 |
_element_klass = _base_element_klass; |
|
50 |
} else { |
|
51 |
_element_klass = NULL; |
|
52 |
} |
|
53 |
if (!ciObjectFactory::is_initialized()) { |
|
54 |
assert(_element_klass->is_java_lang_Object(), "only arrays of object are shared"); |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
// ------------------------------------------------------------------ |
|
59 |
// ciObjArrayKlass::ciObjArrayKlass |
|
60 |
// |
|
61 |
// Constructor for unloaded object array klasses. |
|
62 |
ciObjArrayKlass::ciObjArrayKlass(ciSymbol* array_name, |
|
63 |
ciKlass* base_element_klass, |
|
64 |
int dimension) |
|
65 |
: ciArrayKlass(array_name, |
|
66 |
dimension, |
|
67 |
ciObjArrayKlassKlass::make()) { |
|
68 |
_base_element_klass = base_element_klass; |
|
69 |
assert(_base_element_klass->is_instance_klass() || |
|
70 |
_base_element_klass->is_type_array_klass(), "bad base klass"); |
|
71 |
if (dimension == 1) { |
|
72 |
_element_klass = base_element_klass; |
|
73 |
} else { |
|
74 |
_element_klass = NULL; |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
// ------------------------------------------------------------------ |
|
79 |
// ciObjArrayKlass::element_klass |
|
80 |
// |
|
81 |
// What is the one-level element type of this array? |
|
82 |
ciKlass* ciObjArrayKlass::element_klass() { |
|
83 |
if (_element_klass == NULL) { |
|
84 |
assert(dimension() > 1, "_element_klass should not be NULL"); |
|
85 |
// Produce the element klass. |
|
86 |
if (is_loaded()) { |
|
87 |
VM_ENTRY_MARK; |
|
88 |
klassOop element_klassOop = get_objArrayKlass()->element_klass(); |
|
89 |
_element_klass = CURRENT_THREAD_ENV->get_object(element_klassOop)->as_klass(); |
|
90 |
} else { |
|
91 |
VM_ENTRY_MARK; |
|
92 |
// We are an unloaded array klass. Attempt to fetch our |
|
93 |
// element klass by name. |
|
94 |
_element_klass = CURRENT_THREAD_ENV->get_klass_by_name_impl( |
|
95 |
this, |
|
96 |
construct_array_name(base_element_klass()->name(), |
|
97 |
dimension() - 1), |
|
98 |
false); |
|
99 |
} |
|
100 |
} |
|
101 |
return _element_klass; |
|
102 |
} |
|
103 |
||
104 |
// ------------------------------------------------------------------ |
|
105 |
// ciObjArrayKlass::construct_array_name |
|
106 |
// |
|
107 |
// Build an array name from an element name and a dimension. |
|
108 |
ciSymbol* ciObjArrayKlass::construct_array_name(ciSymbol* element_name, |
|
109 |
int dimension) { |
|
110 |
EXCEPTION_CONTEXT; |
|
111 |
int element_len = element_name->utf8_length(); |
|
112 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
113 |
Symbol* base_name_sym = element_name->get_symbol(); |
1 | 114 |
char* name; |
115 |
||
116 |
if (base_name_sym->byte_at(0) == '[' || |
|
117 |
(base_name_sym->byte_at(0) == 'L' && // watch package name 'Lxx' |
|
118 |
base_name_sym->byte_at(element_len-1) == ';')) { |
|
119 |
||
120 |
int new_len = element_len + dimension + 1; // for the ['s and '\0' |
|
121 |
name = CURRENT_THREAD_ENV->name_buffer(new_len); |
|
122 |
||
123 |
int pos = 0; |
|
124 |
for ( ; pos < dimension; pos++) { |
|
125 |
name[pos] = '['; |
|
126 |
} |
|
127 |
strncpy(name+pos, (char*)element_name->base(), element_len); |
|
128 |
name[new_len-1] = '\0'; |
|
129 |
} else { |
|
130 |
int new_len = 3 // for L, ;, and '\0' |
|
131 |
+ dimension // for ['s |
|
132 |
+ element_len; |
|
133 |
||
134 |
name = CURRENT_THREAD_ENV->name_buffer(new_len); |
|
135 |
int pos = 0; |
|
136 |
for ( ; pos < dimension; pos++) { |
|
137 |
name[pos] = '['; |
|
138 |
} |
|
139 |
name[pos++] = 'L'; |
|
140 |
strncpy(name+pos, (char*)element_name->base(), element_len); |
|
141 |
name[new_len-2] = ';'; |
|
142 |
name[new_len-1] = '\0'; |
|
143 |
} |
|
144 |
return ciSymbol::make(name); |
|
145 |
} |
|
146 |
||
147 |
// ------------------------------------------------------------------ |
|
148 |
// ciObjArrayKlass::make_impl |
|
149 |
// |
|
150 |
// Implementation of make. |
|
151 |
ciObjArrayKlass* ciObjArrayKlass::make_impl(ciKlass* element_klass) { |
|
152 |
||
153 |
if (element_klass->is_loaded()) { |
|
154 |
EXCEPTION_CONTEXT; |
|
155 |
// The element klass is loaded |
|
156 |
klassOop array = element_klass->get_Klass()->array_klass(THREAD); |
|
157 |
if (HAS_PENDING_EXCEPTION) { |
|
158 |
CLEAR_PENDING_EXCEPTION; |
|
159 |
CURRENT_THREAD_ENV->record_out_of_memory_failure(); |
|
160 |
return ciEnv::unloaded_ciobjarrayklass(); |
|
161 |
} |
|
162 |
return CURRENT_THREAD_ENV->get_object(array)->as_obj_array_klass(); |
|
163 |
} |
|
164 |
||
165 |
// The array klass was unable to be made or the element klass was |
|
166 |
// not loaded. |
|
167 |
ciSymbol* array_name = construct_array_name(element_klass->name(), 1); |
|
168 |
if (array_name == ciEnv::unloaded_cisymbol()) { |
|
169 |
return ciEnv::unloaded_ciobjarrayklass(); |
|
170 |
} |
|
171 |
return |
|
172 |
CURRENT_ENV->get_unloaded_klass(element_klass, array_name) |
|
173 |
->as_obj_array_klass(); |
|
174 |
} |
|
175 |
||
176 |
// ------------------------------------------------------------------ |
|
177 |
// ciObjArrayKlass::make |
|
178 |
// |
|
179 |
// Make an array klass corresponding to the specified primitive type. |
|
180 |
ciObjArrayKlass* ciObjArrayKlass::make(ciKlass* element_klass) { |
|
181 |
assert(element_klass->is_java_klass(), "wrong kind of klass"); |
|
182 |
GUARDED_VM_ENTRY(return make_impl(element_klass);) |
|
183 |
} |