comparison src/share/vm/ci/ciStreams.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 7f813940ac35
children f6b0eb4e44cf
comparison
equal deleted inserted replaced
6724:36d1d483d5d6 6725:da91efe96a93
1 /* 1 /*
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "ci/ciCPCache.hpp"
27 #include "ci/ciCallSite.hpp" 26 #include "ci/ciCallSite.hpp"
28 #include "ci/ciConstant.hpp" 27 #include "ci/ciConstant.hpp"
29 #include "ci/ciField.hpp" 28 #include "ci/ciField.hpp"
30 #include "ci/ciStreams.hpp" 29 #include "ci/ciStreams.hpp"
31 #include "ci/ciUtilities.hpp" 30 #include "ci/ciUtilities.hpp"
184 // 183 //
185 // If this bytecode is a new, newarray, multianewarray, instanceof, 184 // If this bytecode is a new, newarray, multianewarray, instanceof,
186 // or checkcast, get the referenced klass. 185 // or checkcast, get the referenced klass.
187 ciKlass* ciBytecodeStream::get_klass(bool& will_link) { 186 ciKlass* ciBytecodeStream::get_klass(bool& will_link) {
188 VM_ENTRY_MARK; 187 VM_ENTRY_MARK;
189 constantPoolHandle cpool(_method->get_methodOop()->constants()); 188 constantPoolHandle cpool(_method->get_Method()->constants());
190 return CURRENT_ENV->get_klass_by_index(cpool, get_klass_index(), will_link, _holder); 189 return CURRENT_ENV->get_klass_by_index(cpool, get_klass_index(), will_link, _holder);
191 } 190 }
192 191
193 // ------------------------------------------------------------------ 192 // ------------------------------------------------------------------
194 // ciBytecodeStream::get_constant_raw_index 193 // ciBytecodeStream::get_constant_raw_index
209 } 208 }
210 } 209 }
211 210
212 // ------------------------------------------------------------------ 211 // ------------------------------------------------------------------
213 // ciBytecodeStream::get_constant_pool_index 212 // ciBytecodeStream::get_constant_pool_index
214 // Decode any CP cache index into a regular pool index. 213 // Decode any reference index into a regular pool index.
215 int ciBytecodeStream::get_constant_pool_index() const { 214 int ciBytecodeStream::get_constant_pool_index() const {
216 // work-alike for Bytecode_loadconstant::pool_index() 215 // work-alike for Bytecode_loadconstant::pool_index()
217 int index = get_constant_raw_index(); 216 int index = get_constant_raw_index();
218 if (has_cache_index()) { 217 if (has_cache_index()) {
219 return get_cpcache()->get_pool_index(index); 218 VM_ENTRY_MARK;
219 constantPoolHandle cpool(_method->get_Method()->constants());
220 return cpool->object_to_cp_index(index);
220 } 221 }
221 return index; 222 return index;
222 } 223 }
223 224
224 // ------------------------------------------------------------------ 225 // ------------------------------------------------------------------
240 if (has_cache_index()) { 241 if (has_cache_index()) {
241 cache_index = pool_index; 242 cache_index = pool_index;
242 pool_index = -1; 243 pool_index = -1;
243 } 244 }
244 VM_ENTRY_MARK; 245 VM_ENTRY_MARK;
245 constantPoolHandle cpool(_method->get_methodOop()->constants()); 246 constantPoolHandle cpool(_method->get_Method()->constants());
246 return CURRENT_ENV->get_constant_by_index(cpool, pool_index, cache_index, _holder); 247 return CURRENT_ENV->get_constant_by_index(cpool, pool_index, cache_index, _holder);
247 } 248 }
248 249
249 // ------------------------------------------------------------------ 250 // ------------------------------------------------------------------
250 // ciBytecodeStream::get_constant_pool_tag 251 // ciBytecodeStream::get_constant_pool_tag
251 // 252 //
252 // If this bytecode is one of the ldc variants, get the referenced 253 // If this bytecode is one of the ldc variants, get the referenced
253 // constant. 254 // constant.
254 constantTag ciBytecodeStream::get_constant_pool_tag(int index) const { 255 constantTag ciBytecodeStream::get_constant_pool_tag(int index) const {
255 VM_ENTRY_MARK; 256 VM_ENTRY_MARK;
256 return _method->get_methodOop()->constants()->tag_at(index); 257 return _method->get_Method()->constants()->tag_at(index);
257 } 258 }
258 259
259 // ------------------------------------------------------------------ 260 // ------------------------------------------------------------------
260 // ciBytecodeStream::get_field_index 261 // ciBytecodeStream::get_field_index
261 // 262 //
293 // 294 //
294 // There is no "will_link" result passed back. The user is responsible 295 // There is no "will_link" result passed back. The user is responsible
295 // for checking linkability when retrieving the associated field. 296 // for checking linkability when retrieving the associated field.
296 ciInstanceKlass* ciBytecodeStream::get_declared_field_holder() { 297 ciInstanceKlass* ciBytecodeStream::get_declared_field_holder() {
297 VM_ENTRY_MARK; 298 VM_ENTRY_MARK;
298 constantPoolHandle cpool(_method->get_methodOop()->constants()); 299 constantPoolHandle cpool(_method->get_Method()->constants());
299 int holder_index = get_field_holder_index(); 300 int holder_index = get_field_holder_index();
300 bool ignore; 301 bool ignore;
301 return CURRENT_ENV->get_klass_by_index(cpool, holder_index, ignore, _holder) 302 return CURRENT_ENV->get_klass_by_index(cpool, holder_index, ignore, _holder)
302 ->as_instance_klass(); 303 ->as_instance_klass();
303 } 304 }
308 // Get the constant pool index of the declared holder of the field 309 // Get the constant pool index of the declared holder of the field
309 // referenced by the current bytecode. Used for generating 310 // referenced by the current bytecode. Used for generating
310 // deoptimization information. 311 // deoptimization information.
311 int ciBytecodeStream::get_field_holder_index() { 312 int ciBytecodeStream::get_field_holder_index() {
312 GUARDED_VM_ENTRY( 313 GUARDED_VM_ENTRY(
313 constantPoolOop cpool = _holder->get_instanceKlass()->constants(); 314 ConstantPool* cpool = _holder->get_instanceKlass()->constants();
314 return cpool->klass_ref_index_at(get_field_index()); 315 return cpool->klass_ref_index_at(get_field_index());
315 ) 316 )
316 } 317 }
317 318
318 // ------------------------------------------------------------------ 319 // ------------------------------------------------------------------
321 // Get the constant pool index of the signature of the field 322 // Get the constant pool index of the signature of the field
322 // referenced by the current bytecode. Used for generating 323 // referenced by the current bytecode. Used for generating
323 // deoptimization information. 324 // deoptimization information.
324 int ciBytecodeStream::get_field_signature_index() { 325 int ciBytecodeStream::get_field_signature_index() {
325 VM_ENTRY_MARK; 326 VM_ENTRY_MARK;
326 constantPoolOop cpool = _holder->get_instanceKlass()->constants(); 327 ConstantPool* cpool = _holder->get_instanceKlass()->constants();
327 int nt_index = cpool->name_and_type_ref_index_at(get_field_index()); 328 int nt_index = cpool->name_and_type_ref_index_at(get_field_index());
328 return cpool->signature_ref_index_at(nt_index); 329 return cpool->signature_ref_index_at(nt_index);
329 } 330 }
330 331
331 // ------------------------------------------------------------------ 332 // ------------------------------------------------------------------
358 // Additionally return the declared signature to get more concrete 359 // Additionally return the declared signature to get more concrete
359 // type information if required (Cf. invokedynamic and invokehandle). 360 // type information if required (Cf. invokedynamic and invokehandle).
360 ciMethod* ciBytecodeStream::get_method(bool& will_link, ciSignature* *declared_signature_result) { 361 ciMethod* ciBytecodeStream::get_method(bool& will_link, ciSignature* *declared_signature_result) {
361 VM_ENTRY_MARK; 362 VM_ENTRY_MARK;
362 ciEnv* env = CURRENT_ENV; 363 ciEnv* env = CURRENT_ENV;
363 constantPoolHandle cpool(_method->get_methodOop()->constants()); 364 constantPoolHandle cpool(_method->get_Method()->constants());
364 ciMethod* m = env->get_method_by_index(cpool, get_method_index(), cur_bc(), _holder); 365 ciMethod* m = env->get_method_by_index(cpool, get_method_index(), cur_bc(), _holder);
365 will_link = m->is_loaded(); 366 will_link = m->is_loaded();
366 // Get declared method signature and return it. 367 // Get declared method signature and return it.
367 if (has_optional_appendix()) { 368 if (has_optional_appendix()) {
368 const int sig_index = get_method_signature_index(); 369 const int sig_index = get_method_signature_index();
369 Symbol* sig_sym = cpool->symbol_at(sig_index); 370 Symbol* sig_sym = cpool->symbol_at(sig_index);
370 ciKlass* pool_holder = env->get_object(cpool->pool_holder())->as_klass(); 371 ciKlass* pool_holder = env->get_klass(cpool->pool_holder());
371 (*declared_signature_result) = new (env->arena()) ciSignature(pool_holder, cpool, env->get_symbol(sig_sym)); 372 (*declared_signature_result) = new (env->arena()) ciSignature(pool_holder, cpool, env->get_symbol(sig_sym));
372 } else { 373 } else {
373 (*declared_signature_result) = m->signature(); 374 (*declared_signature_result) = m->signature();
374 } 375 }
375 return m; 376 return m;
380 // 381 //
381 // Returns true if there is an appendix argument stored in the 382 // Returns true if there is an appendix argument stored in the
382 // constant pool cache at the current bci. 383 // constant pool cache at the current bci.
383 bool ciBytecodeStream::has_appendix() { 384 bool ciBytecodeStream::has_appendix() {
384 VM_ENTRY_MARK; 385 VM_ENTRY_MARK;
385 constantPoolHandle cpool(_method->get_methodOop()->constants()); 386 constantPoolHandle cpool(_method->get_Method()->constants());
386 return constantPoolOopDesc::has_appendix_at_if_loaded(cpool, get_method_index()); 387 return ConstantPool::has_appendix_at_if_loaded(cpool, get_method_index());
387 } 388 }
388 389
389 // ------------------------------------------------------------------ 390 // ------------------------------------------------------------------
390 // ciBytecodeStream::get_appendix 391 // ciBytecodeStream::get_appendix
391 // 392 //
392 // Return the appendix argument stored in the constant pool cache at 393 // Return the appendix argument stored in the constant pool cache at
393 // the current bci. 394 // the current bci.
394 ciObject* ciBytecodeStream::get_appendix() { 395 ciObject* ciBytecodeStream::get_appendix() {
395 VM_ENTRY_MARK; 396 VM_ENTRY_MARK;
396 constantPoolHandle cpool(_method->get_methodOop()->constants()); 397 constantPoolHandle cpool(_method->get_Method()->constants());
397 oop appendix_oop = constantPoolOopDesc::appendix_at_if_loaded(cpool, get_method_index()); 398 oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, get_method_index());
398 return CURRENT_ENV->get_object(appendix_oop); 399 return CURRENT_ENV->get_object(appendix_oop);
399 } 400 }
400 401
401 // ------------------------------------------------------------------ 402 // ------------------------------------------------------------------
402 // ciBytecodeStream::get_declared_method_holder 403 // ciBytecodeStream::get_declared_method_holder
409 // 410 //
410 // There is no "will_link" result passed back. The user is responsible 411 // There is no "will_link" result passed back. The user is responsible
411 // for checking linkability when retrieving the associated method. 412 // for checking linkability when retrieving the associated method.
412 ciKlass* ciBytecodeStream::get_declared_method_holder() { 413 ciKlass* ciBytecodeStream::get_declared_method_holder() {
413 VM_ENTRY_MARK; 414 VM_ENTRY_MARK;
414 constantPoolHandle cpool(_method->get_methodOop()->constants()); 415 constantPoolHandle cpool(_method->get_Method()->constants());
415 bool ignore; 416 bool ignore;
416 // report as MethodHandle for invokedynamic, which is syntactically classless 417 // report as MethodHandle for invokedynamic, which is syntactically classless
417 if (cur_bc() == Bytecodes::_invokedynamic) 418 if (cur_bc() == Bytecodes::_invokedynamic)
418 return CURRENT_ENV->get_klass_by_name(_holder, ciSymbol::java_lang_invoke_MethodHandle(), false); 419 return CURRENT_ENV->get_klass_by_name(_holder, ciSymbol::java_lang_invoke_MethodHandle(), false);
419 return CURRENT_ENV->get_klass_by_index(cpool, get_method_holder_index(), ignore, _holder); 420 return CURRENT_ENV->get_klass_by_index(cpool, get_method_holder_index(), ignore, _holder);
424 // 425 //
425 // Get the constant pool index of the declared holder of the method 426 // Get the constant pool index of the declared holder of the method
426 // referenced by the current bytecode. Used for generating 427 // referenced by the current bytecode. Used for generating
427 // deoptimization information. 428 // deoptimization information.
428 int ciBytecodeStream::get_method_holder_index() { 429 int ciBytecodeStream::get_method_holder_index() {
429 constantPoolOop cpool = _method->get_methodOop()->constants(); 430 ConstantPool* cpool = _method->get_Method()->constants();
430 return cpool->klass_ref_index_at(get_method_index()); 431 return cpool->klass_ref_index_at(get_method_index());
431 } 432 }
432 433
433 // ------------------------------------------------------------------ 434 // ------------------------------------------------------------------
434 // ciBytecodeStream::get_method_signature_index 435 // ciBytecodeStream::get_method_signature_index
436 // Get the constant pool index of the signature of the method 437 // Get the constant pool index of the signature of the method
437 // referenced by the current bytecode. Used for generating 438 // referenced by the current bytecode. Used for generating
438 // deoptimization information. 439 // deoptimization information.
439 int ciBytecodeStream::get_method_signature_index() { 440 int ciBytecodeStream::get_method_signature_index() {
440 GUARDED_VM_ENTRY( 441 GUARDED_VM_ENTRY(
441 constantPoolOop cpool = _holder->get_instanceKlass()->constants(); 442 ConstantPool* cpool = _holder->get_instanceKlass()->constants();
442 const int method_index = get_method_index(); 443 const int method_index = get_method_index();
443 const int name_and_type_index = cpool->name_and_type_ref_index_at(method_index); 444 const int name_and_type_index = cpool->name_and_type_ref_index_at(method_index);
444 return cpool->signature_ref_index_at(name_and_type_index); 445 return cpool->signature_ref_index_at(name_and_type_index);
445 ) 446 )
446 } 447 }
447 448
448 // ------------------------------------------------------------------ 449 // ------------------------------------------------------------------
449 // ciBytecodeStream::get_cpcache 450 // ciBytecodeStream::get_resolved_references
450 ciCPCache* ciBytecodeStream::get_cpcache() const { 451 ciObjArray* ciBytecodeStream::get_resolved_references() {
451 if (_cpcache == NULL) {
452 VM_ENTRY_MARK; 452 VM_ENTRY_MARK;
453 // Get the constant pool. 453 // Get the constant pool.
454 constantPoolOop cpool = _holder->get_instanceKlass()->constants(); 454 ConstantPool* cpool = _holder->get_instanceKlass()->constants();
455 constantPoolCacheOop cpcache = cpool->cache(); 455
456 456 // Create a resolved references array and return it.
457 *(ciCPCache**)&_cpcache = CURRENT_ENV->get_object(cpcache)->as_cpcache(); 457 return CURRENT_ENV->get_object(cpool->resolved_references())->as_obj_array();
458 } 458 }
459 return _cpcache;
460 }
461
462 // ------------------------------------------------------------------
463 // ciBytecodeStream::get_call_site
464 ciCallSite* ciBytecodeStream::get_call_site() {
465 VM_ENTRY_MARK;
466 // Get the constant pool.
467 constantPoolOop cpool = _holder->get_instanceKlass()->constants();
468 constantPoolCacheOop cpcache = cpool->cache();
469
470 // Get the CallSite from the constant pool cache.
471 int method_index = get_method_index();
472 ConstantPoolCacheEntry* cpcache_entry = cpcache->secondary_entry_at(method_index);
473 oop call_site_oop = cpcache_entry->f1_as_instance();
474
475 // Create a CallSite object and return it.
476 return CURRENT_ENV->get_object(call_site_oop)->as_call_site();
477 }