Mercurial > hg > graal-jvmci-8
comparison jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotConstantPool.java @ 22582:232c53e17ea0
added CompilerToVM.compilerToVM() for static access to the CompilerToVM instance
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 18 Sep 2015 15:16:15 +0200 |
parents | 3884a98ebcde |
children | ed53e370f04c |
comparison
equal
deleted
inserted
replaced
22581:3884a98ebcde | 22582:232c53e17ea0 |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package jdk.internal.jvmci.hotspot; | 23 package jdk.internal.jvmci.hotspot; |
24 | 24 |
25 import static jdk.internal.jvmci.hotspot.CompilerToVM.compilerToVM; | |
25 import static jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime.runtime; | 26 import static jdk.internal.jvmci.hotspot.HotSpotJVMCIRuntime.runtime; |
26 import static jdk.internal.jvmci.hotspot.HotSpotVMConfig.config; | 27 import static jdk.internal.jvmci.hotspot.HotSpotVMConfig.config; |
27 import static jdk.internal.jvmci.hotspot.UnsafeAccess.UNSAFE; | 28 import static jdk.internal.jvmci.hotspot.UnsafeAccess.UNSAFE; |
28 | 29 |
29 import java.lang.invoke.MethodHandle; | 30 import java.lang.invoke.MethodHandle; |
206 * Gets the holder for this constant pool as {@link HotSpotResolvedObjectTypeImpl}. | 207 * Gets the holder for this constant pool as {@link HotSpotResolvedObjectTypeImpl}. |
207 * | 208 * |
208 * @return holder for this constant pool | 209 * @return holder for this constant pool |
209 */ | 210 */ |
210 private HotSpotResolvedObjectType getHolder() { | 211 private HotSpotResolvedObjectType getHolder() { |
211 return runtime().getCompilerToVM().getResolvedJavaType(this, config().constantPoolHolderOffset, false); | 212 return compilerToVM().getResolvedJavaType(this, config().constantPoolHolderOffset, false); |
212 } | 213 } |
213 | 214 |
214 /** | 215 /** |
215 * Converts a raw index from the bytecodes to a constant pool index by adding a | 216 * Converts a raw index from the bytecodes to a constant pool index by adding a |
216 * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}. | 217 * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}. |
361 * | 362 * |
362 * @param index constant pool index | 363 * @param index constant pool index |
363 * @return {@code JVM_CONSTANT_NameAndType} reference constant pool entry | 364 * @return {@code JVM_CONSTANT_NameAndType} reference constant pool entry |
364 */ | 365 */ |
365 private int getNameAndTypeRefIndexAt(int index) { | 366 private int getNameAndTypeRefIndexAt(int index) { |
366 return runtime().getCompilerToVM().lookupNameAndTypeRefIndexInPool(this, index); | 367 return compilerToVM().lookupNameAndTypeRefIndexInPool(this, index); |
367 } | 368 } |
368 | 369 |
369 /** | 370 /** |
370 * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index | 371 * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index |
371 * {@code index}. | 372 * {@code index}. |
372 * | 373 * |
373 * @param index constant pool index | 374 * @param index constant pool index |
374 * @return name as {@link String} | 375 * @return name as {@link String} |
375 */ | 376 */ |
376 private String getNameRefAt(int index) { | 377 private String getNameRefAt(int index) { |
377 return runtime().getCompilerToVM().lookupNameRefInPool(this, index); | 378 return compilerToVM().lookupNameRefInPool(this, index); |
378 } | 379 } |
379 | 380 |
380 /** | 381 /** |
381 * Gets the name reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry at | 382 * Gets the name reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry at |
382 * index {@code index}. | 383 * index {@code index}. |
396 * | 397 * |
397 * @param index constant pool index | 398 * @param index constant pool index |
398 * @return signature as {@link String} | 399 * @return signature as {@link String} |
399 */ | 400 */ |
400 private String getSignatureRefAt(int index) { | 401 private String getSignatureRefAt(int index) { |
401 return runtime().getCompilerToVM().lookupSignatureRefInPool(this, index); | 402 return compilerToVM().lookupSignatureRefInPool(this, index); |
402 } | 403 } |
403 | 404 |
404 /** | 405 /** |
405 * Gets the signature reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry | 406 * Gets the signature reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry |
406 * at index {@code index}. | 407 * at index {@code index}. |
419 * | 420 * |
420 * @param index constant pool index | 421 * @param index constant pool index |
421 * @return klass reference index | 422 * @return klass reference index |
422 */ | 423 */ |
423 private int getKlassRefIndexAt(int index) { | 424 private int getKlassRefIndexAt(int index) { |
424 return runtime().getCompilerToVM().lookupKlassRefIndexInPool(this, index); | 425 return compilerToVM().lookupKlassRefIndexInPool(this, index); |
425 } | 426 } |
426 | 427 |
427 /** | 428 /** |
428 * Gets the uncached klass reference index constant pool entry at index {@code index}. See: | 429 * Gets the uncached klass reference index constant pool entry at index {@code index}. See: |
429 * {@code ConstantPool::uncached_klass_ref_index_at}. | 430 * {@code ConstantPool::uncached_klass_ref_index_at}. |
496 /* | 497 /* |
497 * Normally, we would expect a String here, but anonymous classes can have | 498 * Normally, we would expect a String here, but anonymous classes can have |
498 * "pseudo strings" (arbitrary live objects) patched into a String entry. Such | 499 * "pseudo strings" (arbitrary live objects) patched into a String entry. Such |
499 * entries do not have a symbol in the constant pool slot. | 500 * entries do not have a symbol in the constant pool slot. |
500 */ | 501 */ |
501 Object string = runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(this, cpi); | 502 Object string = compilerToVM().resolvePossiblyCachedConstantInPool(this, cpi); |
502 return HotSpotObjectConstantImpl.forObject(string); | 503 return HotSpotObjectConstantImpl.forObject(string); |
503 case MethodHandle: | 504 case MethodHandle: |
504 case MethodHandleInError: | 505 case MethodHandleInError: |
505 case MethodType: | 506 case MethodType: |
506 case MethodTypeInError: | 507 case MethodTypeInError: |
507 Object obj = runtime().getCompilerToVM().resolveConstantInPool(this, cpi); | 508 Object obj = compilerToVM().resolveConstantInPool(this, cpi); |
508 return HotSpotObjectConstantImpl.forObject(obj); | 509 return HotSpotObjectConstantImpl.forObject(obj); |
509 default: | 510 default: |
510 throw new JVMCIError("Unknown constant pool tag %s", tag); | 511 throw new JVMCIError("Unknown constant pool tag %s", tag); |
511 } | 512 } |
512 } | 513 } |
513 | 514 |
514 @Override | 515 @Override |
515 public String lookupUtf8(int cpi) { | 516 public String lookupUtf8(int cpi) { |
516 assertTag(cpi, JVM_CONSTANT.Utf8); | 517 assertTag(cpi, JVM_CONSTANT.Utf8); |
517 return runtime().getCompilerToVM().getSymbol(getEntryAt(cpi)); | 518 return compilerToVM().getSymbol(getEntryAt(cpi)); |
518 } | 519 } |
519 | 520 |
520 @Override | 521 @Override |
521 public Signature lookupSignature(int cpi) { | 522 public Signature lookupSignature(int cpi) { |
522 return new HotSpotSignature(runtime(), lookupUtf8(cpi)); | 523 return new HotSpotSignature(runtime(), lookupUtf8(cpi)); |
524 | 525 |
525 @Override | 526 @Override |
526 public JavaConstant lookupAppendix(int cpi, int opcode) { | 527 public JavaConstant lookupAppendix(int cpi, int opcode) { |
527 assert Bytecodes.isInvoke(opcode); | 528 assert Bytecodes.isInvoke(opcode); |
528 final int index = rawIndexToConstantPoolIndex(cpi, opcode); | 529 final int index = rawIndexToConstantPoolIndex(cpi, opcode); |
529 Object appendix = runtime().getCompilerToVM().lookupAppendixInPool(this, index); | 530 Object appendix = compilerToVM().lookupAppendixInPool(this, index); |
530 if (appendix == null) { | 531 if (appendix == null) { |
531 return null; | 532 return null; |
532 } else { | 533 } else { |
533 return HotSpotObjectConstantImpl.forObject(appendix); | 534 return HotSpotObjectConstantImpl.forObject(appendix); |
534 } | 535 } |
549 } | 550 } |
550 | 551 |
551 @Override | 552 @Override |
552 public JavaMethod lookupMethod(int cpi, int opcode) { | 553 public JavaMethod lookupMethod(int cpi, int opcode) { |
553 final int index = rawIndexToConstantPoolIndex(cpi, opcode); | 554 final int index = rawIndexToConstantPoolIndex(cpi, opcode); |
554 final HotSpotResolvedJavaMethod method = runtime().getCompilerToVM().lookupMethodInPool(this, index, (byte) opcode); | 555 final HotSpotResolvedJavaMethod method = compilerToVM().lookupMethodInPool(this, index, (byte) opcode); |
555 if (method != null) { | 556 if (method != null) { |
556 return method; | 557 return method; |
557 } else { | 558 } else { |
558 // Get the method's name and signature. | 559 // Get the method's name and signature. |
559 String name = getNameRefAt(index); | 560 String name = getNameRefAt(index); |
561 if (opcode == Bytecodes.INVOKEDYNAMIC) { | 562 if (opcode == Bytecodes.INVOKEDYNAMIC) { |
562 HotSpotResolvedObjectType holder = HotSpotResolvedObjectTypeImpl.fromObjectClass(MethodHandle.class); | 563 HotSpotResolvedObjectType holder = HotSpotResolvedObjectTypeImpl.fromObjectClass(MethodHandle.class); |
563 return new HotSpotMethodUnresolved(name, signature, holder); | 564 return new HotSpotMethodUnresolved(name, signature, holder); |
564 } else { | 565 } else { |
565 final int klassIndex = getKlassRefIndexAt(index); | 566 final int klassIndex = getKlassRefIndexAt(index); |
566 final Object type = runtime().getCompilerToVM().lookupKlassInPool(this, klassIndex); | 567 final Object type = compilerToVM().lookupKlassInPool(this, klassIndex); |
567 JavaType holder = getJavaType(type); | 568 JavaType holder = getJavaType(type); |
568 return new HotSpotMethodUnresolved(name, signature, holder); | 569 return new HotSpotMethodUnresolved(name, signature, holder); |
569 } | 570 } |
570 } | 571 } |
571 } | 572 } |
574 public JavaType lookupType(int cpi, int opcode) { | 575 public JavaType lookupType(int cpi, int opcode) { |
575 final LookupTypeCacheElement elem = this.lastLookupType; | 576 final LookupTypeCacheElement elem = this.lastLookupType; |
576 if (elem != null && elem.lastCpi == cpi) { | 577 if (elem != null && elem.lastCpi == cpi) { |
577 return elem.javaType; | 578 return elem.javaType; |
578 } else { | 579 } else { |
579 final Object type = runtime().getCompilerToVM().lookupKlassInPool(this, cpi); | 580 final Object type = compilerToVM().lookupKlassInPool(this, cpi); |
580 JavaType result = getJavaType(type); | 581 JavaType result = getJavaType(type); |
581 if (result instanceof ResolvedJavaType) { | 582 if (result instanceof ResolvedJavaType) { |
582 this.lastLookupType = new LookupTypeCacheElement(cpi, result); | 583 this.lastLookupType = new LookupTypeCacheElement(cpi, result); |
583 } | 584 } |
584 return result; | 585 return result; |
600 | 601 |
601 if (holder instanceof HotSpotResolvedObjectTypeImpl) { | 602 if (holder instanceof HotSpotResolvedObjectTypeImpl) { |
602 long[] info = new long[2]; | 603 long[] info = new long[2]; |
603 HotSpotResolvedObjectTypeImpl resolvedHolder; | 604 HotSpotResolvedObjectTypeImpl resolvedHolder; |
604 try { | 605 try { |
605 resolvedHolder = runtime().getCompilerToVM().resolveFieldInPool(this, index, (byte) opcode, info); | 606 resolvedHolder = compilerToVM().resolveFieldInPool(this, index, (byte) opcode, info); |
606 } catch (Throwable t) { | 607 } catch (Throwable t) { |
607 /* | 608 /* |
608 * If there was an exception resolving the field we give up and return an unresolved | 609 * If there was an exception resolving the field we give up and return an unresolved |
609 * field. | 610 * field. |
610 */ | 611 */ |
635 index = cpi; | 636 index = cpi; |
636 break; | 637 break; |
637 case Bytecodes.INVOKEDYNAMIC: { | 638 case Bytecodes.INVOKEDYNAMIC: { |
638 // invokedynamic instructions point to a constant pool cache entry. | 639 // invokedynamic instructions point to a constant pool cache entry. |
639 index = decodeConstantPoolCacheIndex(cpi) + config().constantPoolCpCacheIndexTag; | 640 index = decodeConstantPoolCacheIndex(cpi) + config().constantPoolCpCacheIndexTag; |
640 index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(this, index); | 641 index = compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index); |
641 break; | 642 break; |
642 } | 643 } |
643 case Bytecodes.GETSTATIC: | 644 case Bytecodes.GETSTATIC: |
644 case Bytecodes.PUTSTATIC: | 645 case Bytecodes.PUTSTATIC: |
645 case Bytecodes.GETFIELD: | 646 case Bytecodes.GETFIELD: |
648 case Bytecodes.INVOKESPECIAL: | 649 case Bytecodes.INVOKESPECIAL: |
649 case Bytecodes.INVOKESTATIC: | 650 case Bytecodes.INVOKESTATIC: |
650 case Bytecodes.INVOKEINTERFACE: { | 651 case Bytecodes.INVOKEINTERFACE: { |
651 // invoke and field instructions point to a constant pool cache entry. | 652 // invoke and field instructions point to a constant pool cache entry. |
652 index = rawIndexToConstantPoolIndex(cpi, opcode); | 653 index = rawIndexToConstantPoolIndex(cpi, opcode); |
653 index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(this, index); | 654 index = compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index); |
654 break; | 655 break; |
655 } | 656 } |
656 default: | 657 default: |
657 throw JVMCIError.shouldNotReachHere("Unexpected opcode " + opcode); | 658 throw JVMCIError.shouldNotReachHere("Unexpected opcode " + opcode); |
658 } | 659 } |
672 assert klassTag == JVM_CONSTANT.Class || klassTag == JVM_CONSTANT.UnresolvedClass || klassTag == JVM_CONSTANT.UnresolvedClassInError : klassTag; | 673 assert klassTag == JVM_CONSTANT.Class || klassTag == JVM_CONSTANT.UnresolvedClass || klassTag == JVM_CONSTANT.UnresolvedClassInError : klassTag; |
673 // fall through | 674 // fall through |
674 case Class: | 675 case Class: |
675 case UnresolvedClass: | 676 case UnresolvedClass: |
676 case UnresolvedClassInError: | 677 case UnresolvedClassInError: |
677 final HotSpotResolvedObjectTypeImpl type = runtime().getCompilerToVM().resolveTypeInPool(this, index); | 678 final HotSpotResolvedObjectTypeImpl type = compilerToVM().resolveTypeInPool(this, index); |
678 Class<?> klass = type.mirror(); | 679 Class<?> klass = type.mirror(); |
679 if (!klass.isPrimitive() && !klass.isArray()) { | 680 if (!klass.isPrimitive() && !klass.isArray()) { |
680 UNSAFE.ensureClassInitialized(klass); | 681 UNSAFE.ensureClassInitialized(klass); |
681 } | 682 } |
682 switch (tag) { | 683 switch (tag) { |
683 case MethodRef: | 684 case MethodRef: |
684 if (Bytecodes.isInvokeHandleAlias(opcode)) { | 685 if (Bytecodes.isInvokeHandleAlias(opcode)) { |
685 final int methodRefCacheIndex = rawIndexToConstantPoolIndex(cpi, opcode); | 686 final int methodRefCacheIndex = rawIndexToConstantPoolIndex(cpi, opcode); |
686 if (isInvokeHandle(methodRefCacheIndex, type)) { | 687 if (isInvokeHandle(methodRefCacheIndex, type)) { |
687 runtime().getCompilerToVM().resolveInvokeHandleInPool(this, methodRefCacheIndex); | 688 compilerToVM().resolveInvokeHandleInPool(this, methodRefCacheIndex); |
688 } | 689 } |
689 } | 690 } |
690 } | 691 } |
691 break; | 692 break; |
692 case InvokeDynamic: | 693 case InvokeDynamic: |
693 if (isInvokedynamicIndex(cpi)) { | 694 if (isInvokedynamicIndex(cpi)) { |
694 runtime().getCompilerToVM().resolveInvokeDynamicInPool(this, cpi); | 695 compilerToVM().resolveInvokeDynamicInPool(this, cpi); |
695 } | 696 } |
696 break; | 697 break; |
697 default: | 698 default: |
698 // nothing | 699 // nothing |
699 break; | 700 break; |
700 } | 701 } |
701 } | 702 } |
702 | 703 |
703 private boolean isInvokeHandle(int methodRefCacheIndex, HotSpotResolvedObjectTypeImpl klass) { | 704 private boolean isInvokeHandle(int methodRefCacheIndex, HotSpotResolvedObjectTypeImpl klass) { |
704 assertTag(runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(this, methodRefCacheIndex), JVM_CONSTANT.MethodRef); | 705 assertTag(compilerToVM().constantPoolRemapInstructionOperandFromCache(this, methodRefCacheIndex), JVM_CONSTANT.MethodRef); |
705 return ResolvedJavaMethod.isSignaturePolymorphic(klass, getNameRefAt(methodRefCacheIndex), runtime().getHostJVMCIBackend().getMetaAccess()); | 706 return ResolvedJavaMethod.isSignaturePolymorphic(klass, getNameRefAt(methodRefCacheIndex), runtime().getHostJVMCIBackend().getMetaAccess()); |
706 } | 707 } |
707 | 708 |
708 @Override | 709 @Override |
709 public String toString() { | 710 public String toString() { |