Wed, 23 Jan 2013 13:02:39 -0500
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS.
Reviewed-by: coleenp, stefank
1 /*
2 * Copyright (c) 2003, 2012, 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 */
25 #include "precompiled.hpp"
26 #include "interpreter/interpreter.hpp"
27 #include "memory/gcLocker.hpp"
28 #include "memory/metadataFactory.hpp"
29 #include "oops/constMethod.hpp"
30 #include "oops/method.hpp"
32 // Static initialization
33 const u2 ConstMethod::MAX_IDNUM = 0xFFFE;
34 const u2 ConstMethod::UNSET_IDNUM = 0xFFFF;
36 ConstMethod* ConstMethod::allocate(ClassLoaderData* loader_data,
37 int byte_code_size,
38 int compressed_line_number_size,
39 int localvariable_table_length,
40 int exception_table_length,
41 int checked_exceptions_length,
42 int method_parameters_length,
43 u2 generic_signature_index,
44 MethodType method_type,
45 TRAPS) {
46 int size = ConstMethod::size(byte_code_size,
47 compressed_line_number_size,
48 localvariable_table_length,
49 exception_table_length,
50 checked_exceptions_length,
51 method_parameters_length,
52 generic_signature_index);
53 return new (loader_data, size, true, THREAD) ConstMethod(
54 byte_code_size, compressed_line_number_size, localvariable_table_length,
55 exception_table_length, checked_exceptions_length,
56 method_parameters_length, generic_signature_index,
57 method_type, size);
58 }
60 ConstMethod::ConstMethod(int byte_code_size,
61 int compressed_line_number_size,
62 int localvariable_table_length,
63 int exception_table_length,
64 int checked_exceptions_length,
65 int method_parameters_length,
66 u2 generic_signature_index,
67 MethodType method_type,
68 int size) {
70 No_Safepoint_Verifier no_safepoint;
71 set_interpreter_kind(Interpreter::invalid);
72 init_fingerprint();
73 set_constants(NULL);
74 set_stackmap_data(NULL);
75 set_code_size(byte_code_size);
76 set_constMethod_size(size);
77 set_inlined_tables_length(generic_signature_index,
78 checked_exceptions_length,
79 compressed_line_number_size,
80 localvariable_table_length,
81 exception_table_length,
82 method_parameters_length);
83 set_method_type(method_type);
84 assert(this->size() == size, "wrong size for object");
85 }
88 // Deallocate metadata fields associated with ConstMethod*
89 void ConstMethod::deallocate_contents(ClassLoaderData* loader_data) {
90 set_interpreter_kind(Interpreter::invalid);
91 if (stackmap_data() != NULL) {
92 MetadataFactory::free_array<u1>(loader_data, stackmap_data());
93 }
94 set_stackmap_data(NULL);
95 }
97 // How big must this constMethodObject be?
99 int ConstMethod::size(int code_size,
100 int compressed_line_number_size,
101 int local_variable_table_length,
102 int exception_table_length,
103 int checked_exceptions_length,
104 int method_parameters_length,
105 u2 generic_signature_index) {
106 int extra_bytes = code_size;
107 if (compressed_line_number_size > 0) {
108 extra_bytes += compressed_line_number_size;
109 }
110 if (checked_exceptions_length > 0) {
111 extra_bytes += sizeof(u2);
112 extra_bytes += checked_exceptions_length * sizeof(CheckedExceptionElement);
113 }
114 if (local_variable_table_length > 0) {
115 extra_bytes += sizeof(u2);
116 extra_bytes +=
117 local_variable_table_length * sizeof(LocalVariableTableElement);
118 }
119 if (exception_table_length > 0) {
120 extra_bytes += sizeof(u2);
121 extra_bytes += exception_table_length * sizeof(ExceptionTableElement);
122 }
123 if (generic_signature_index != 0) {
124 extra_bytes += sizeof(u2);
125 }
126 if (method_parameters_length > 0) {
127 extra_bytes += sizeof(u2);
128 extra_bytes += method_parameters_length * sizeof(MethodParametersElement);
129 }
130 int extra_words = align_size_up(extra_bytes, BytesPerWord) / BytesPerWord;
131 return align_object_size(header_size() + extra_words);
132 }
134 Method* ConstMethod::method() const {
135 return _constants->pool_holder()->method_with_idnum(_method_idnum);
136 }
138 // linenumber table - note that length is unknown until decompression,
139 // see class CompressedLineNumberReadStream.
141 u_char* ConstMethod::compressed_linenumber_table() const {
142 // Located immediately following the bytecodes.
143 assert(has_linenumber_table(), "called only if table is present");
144 return code_end();
145 }
147 u2* ConstMethod::generic_signature_index_addr() const {
148 // Located at the end of the constMethod.
149 assert(has_generic_signature(), "called only if generic signature exists");
150 return last_u2_element();
151 }
153 u2* ConstMethod::checked_exceptions_length_addr() const {
154 // Located immediately before the generic signature index.
155 assert(has_checked_exceptions(), "called only if table is present");
156 if(has_method_parameters()) {
157 // If method parameters present, locate immediately before them.
158 return (u2*)method_parameters_start() - 1;
159 } else {
160 // Else, the exception table is at the end of the constMethod.
161 return has_generic_signature() ? (last_u2_element() - 1) :
162 last_u2_element();
163 }
164 }
166 u2* ConstMethod::method_parameters_length_addr() const {
167 assert(has_method_parameters(), "called only if table is present");
168 return has_generic_signature() ? (last_u2_element() - 1) :
169 last_u2_element();
170 }
172 u2* ConstMethod::exception_table_length_addr() const {
173 assert(has_exception_handler(), "called only if table is present");
174 if (has_checked_exceptions()) {
175 // If checked_exception present, locate immediately before them.
176 return (u2*) checked_exceptions_start() - 1;
177 } else {
178 if(has_method_parameters()) {
179 // If method parameters present, locate immediately before them.
180 return (u2*)method_parameters_start() - 1;
181 } else {
182 // Else, the exception table is at the end of the constMethod.
183 return has_generic_signature() ? (last_u2_element() - 1) :
184 last_u2_element();
185 }
186 }
187 }
189 u2* ConstMethod::localvariable_table_length_addr() const {
190 assert(has_localvariable_table(), "called only if table is present");
191 if (has_exception_handler()) {
192 // If exception_table present, locate immediately before them.
193 return (u2*) exception_table_start() - 1;
194 } else {
195 if (has_checked_exceptions()) {
196 // If checked_exception present, locate immediately before them.
197 return (u2*) checked_exceptions_start() - 1;
198 } else {
199 if(has_method_parameters()) {
200 // If method parameters present, locate immediately before them.
201 return (u2*)method_parameters_start() - 1;
202 } else {
203 // Else, the exception table is at the end of the constMethod.
204 return has_generic_signature() ? (last_u2_element() - 1) :
205 last_u2_element();
206 }
207 }
208 }
209 }
211 // Update the flags to indicate the presence of these optional fields.
212 void ConstMethod::set_inlined_tables_length(u2 generic_signature_index,
213 int checked_exceptions_len,
214 int compressed_line_number_size,
215 int localvariable_table_len,
216 int exception_table_len,
217 int method_parameters_len) {
218 assert(_flags == 0, "Error");
219 if (compressed_line_number_size > 0)
220 _flags |= _has_linenumber_table;
221 if (generic_signature_index != 0)
222 _flags |= _has_generic_signature;
223 if (method_parameters_len > 0)
224 _flags |= _has_method_parameters;
225 if (checked_exceptions_len > 0)
226 _flags |= _has_checked_exceptions;
227 if (exception_table_len > 0)
228 _flags |= _has_exception_table;
229 if (localvariable_table_len > 0)
230 _flags |= _has_localvariable_table;
232 // This code is extremely brittle and should possibly be revised.
233 // The *_length_addr functions walk backwards through the
234 // constMethod data, using each of the length indexes ahead of them,
235 // as well as the flags variable. Therefore, the indexes must be
236 // initialized in reverse order, or else they will compute the wrong
237 // offsets. Moving the initialization of _flags into a separate
238 // block solves *half* of the problem, but the following part will
239 // still break if the order is not exactly right.
240 //
241 // Also, the servicability agent needs to be informed anytime
242 // anything is added here. It might be advisable to have some sort
243 // of indication of this inline.
244 if (generic_signature_index != 0)
245 *(generic_signature_index_addr()) = generic_signature_index;
246 // New data should probably go here.
247 if (method_parameters_len > 0)
248 *(method_parameters_length_addr()) = method_parameters_len;
249 if (checked_exceptions_len > 0)
250 *(checked_exceptions_length_addr()) = checked_exceptions_len;
251 if (exception_table_len > 0)
252 *(exception_table_length_addr()) = exception_table_len;
253 if (localvariable_table_len > 0)
254 *(localvariable_table_length_addr()) = localvariable_table_len;
255 }
257 int ConstMethod::method_parameters_length() const {
258 return has_method_parameters() ? *(method_parameters_length_addr()) : 0;
259 }
261 MethodParametersElement* ConstMethod::method_parameters_start() const {
262 u2* addr = method_parameters_length_addr();
263 u2 length = *addr;
264 assert(length > 0, "should only be called if table is present");
265 addr -= length * sizeof(MethodParametersElement) / sizeof(u2);
266 return (MethodParametersElement*) addr;
267 }
270 int ConstMethod::checked_exceptions_length() const {
271 return has_checked_exceptions() ? *(checked_exceptions_length_addr()) : 0;
272 }
275 CheckedExceptionElement* ConstMethod::checked_exceptions_start() const {
276 u2* addr = checked_exceptions_length_addr();
277 u2 length = *addr;
278 assert(length > 0, "should only be called if table is present");
279 addr -= length * sizeof(CheckedExceptionElement) / sizeof(u2);
280 return (CheckedExceptionElement*) addr;
281 }
284 int ConstMethod::localvariable_table_length() const {
285 return has_localvariable_table() ? *(localvariable_table_length_addr()) : 0;
286 }
289 LocalVariableTableElement* ConstMethod::localvariable_table_start() const {
290 u2* addr = localvariable_table_length_addr();
291 u2 length = *addr;
292 assert(length > 0, "should only be called if table is present");
293 addr -= length * sizeof(LocalVariableTableElement) / sizeof(u2);
294 return (LocalVariableTableElement*) addr;
295 }
297 int ConstMethod::exception_table_length() const {
298 return has_exception_handler() ? *(exception_table_length_addr()) : 0;
299 }
301 ExceptionTableElement* ConstMethod::exception_table_start() const {
302 u2* addr = exception_table_length_addr();
303 u2 length = *addr;
304 assert(length > 0, "should only be called if table is present");
305 addr -= length * sizeof(ExceptionTableElement) / sizeof(u2);
306 return (ExceptionTableElement*)addr;
307 }
310 // Printing
312 void ConstMethod::print_on(outputStream* st) const {
313 ResourceMark rm;
314 assert(is_constMethod(), "must be constMethod");
315 st->print_cr(internal_name());
316 st->print(" - method: " INTPTR_FORMAT " ", (address)method());
317 method()->print_value_on(st); st->cr();
318 if (has_stackmap_table()) {
319 st->print(" - stackmap data: ");
320 stackmap_data()->print_value_on(st);
321 st->cr();
322 }
323 }
325 // Short version of printing ConstMethod* - just print the name of the
326 // method it belongs to.
327 void ConstMethod::print_value_on(outputStream* st) const {
328 assert(is_constMethod(), "must be constMethod");
329 st->print(" const part of method " );
330 method()->print_value_on(st);
331 }
334 // Verification
336 void ConstMethod::verify_on(outputStream* st) {
337 guarantee(is_constMethod(), "object must be constMethod");
338 guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
340 // Verification can occur during oop construction before the method or
341 // other fields have been initialized.
342 guarantee(is_metadata(), err_msg("Should be metadata " PTR_FORMAT, this));
343 guarantee(method()->is_method(), "should be method");
345 address m_end = (address)((oop*) this + size());
346 address compressed_table_start = code_end();
347 guarantee(compressed_table_start <= m_end, "invalid method layout");
348 address compressed_table_end = compressed_table_start;
349 // Verify line number table
350 if (has_linenumber_table()) {
351 CompressedLineNumberReadStream stream(compressed_linenumber_table());
352 while (stream.read_pair()) {
353 guarantee(stream.bci() >= 0 && stream.bci() <= code_size(), "invalid bci in line number table");
354 }
355 compressed_table_end += stream.position();
356 }
357 guarantee(compressed_table_end <= m_end, "invalid method layout");
358 // Verify checked exceptions, exception table and local variable tables
359 if (has_method_parameters()) {
360 u2* addr = method_parameters_length_addr();
361 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
362 }
363 if (has_checked_exceptions()) {
364 u2* addr = checked_exceptions_length_addr();
365 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
366 }
367 if (has_exception_handler()) {
368 u2* addr = exception_table_length_addr();
369 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
370 }
371 if (has_localvariable_table()) {
372 u2* addr = localvariable_table_length_addr();
373 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
374 }
375 // Check compressed_table_end relative to uncompressed_table_start
376 u2* uncompressed_table_start;
377 if (has_localvariable_table()) {
378 uncompressed_table_start = (u2*) localvariable_table_start();
379 } else if (has_exception_handler()) {
380 uncompressed_table_start = (u2*) exception_table_start();
381 } else if (has_checked_exceptions()) {
382 uncompressed_table_start = (u2*) checked_exceptions_start();
383 } else if (has_method_parameters()) {
384 uncompressed_table_start = (u2*) method_parameters_start();
385 } else {
386 uncompressed_table_start = (u2*) m_end;
387 }
388 int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
389 int max_gap = align_object_size(1)*BytesPerWord;
390 guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
391 }