1 /*
2 * Copyright (c) 2011, 2017, 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 */
646 /*
647 * Converts a raw index from the bytecodes to a constant pool index
648 * (not a cache index).
649 *
650 * @param rawIndex index from the bytecode
651 * @param opcode bytecode to convert the index for
652 * @return constant pool index
653 */
654 public int rawIndexToConstantPoolIndex(int index, int opcode) {
655 if (isInvokedynamicIndex(index)) {
656 assert opcode == Bytecodes.INVOKEDYNAMIC;
657 index = decodeInvokedynamicIndex(index) + config().constantPoolCpCacheIndexTag;
658 } else {
659 assert opcode != Bytecodes.INVOKEDYNAMIC;
660 index = rawIndexToConstantPoolCacheIndex(index, opcode);
661 }
662 return compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index);
663 }
664
665 @Override
666 @SuppressWarnings("fallthrough")
667 public void loadReferencedType(int cpi, int opcode) {
668 int index;
669 switch (opcode) {
670 case Bytecodes.CHECKCAST:
671 case Bytecodes.INSTANCEOF:
672 case Bytecodes.NEW:
673 case Bytecodes.ANEWARRAY:
674 case Bytecodes.MULTIANEWARRAY:
675 case Bytecodes.LDC:
676 case Bytecodes.LDC_W:
677 case Bytecodes.LDC2_W:
678 index = cpi;
679 break;
680 case Bytecodes.INVOKEDYNAMIC: {
681 // invokedynamic instructions point to a constant pool cache entry.
682 index = decodeConstantPoolCacheIndex(cpi) + config().constantPoolCpCacheIndexTag;
683 index = compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index);
684 break;
685 }
686 case Bytecodes.GETSTATIC:
687 case Bytecodes.PUTSTATIC:
701 }
702
703 final JVM_CONSTANT tag = getTagAt(index);
704 if (tag == null) {
705 assert getTagAt(index - 1) == JVM_CONSTANT.Double || getTagAt(index - 1) == JVM_CONSTANT.Long;
706 return;
707 }
708 switch (tag) {
709 case MethodRef:
710 case Fieldref:
711 case InterfaceMethodref:
712 index = getUncachedKlassRefIndexAt(index);
713 // Read the tag only once because it could change between multiple reads.
714 final JVM_CONSTANT klassTag = getTagAt(index);
715 assert klassTag == JVM_CONSTANT.Class || klassTag == JVM_CONSTANT.UnresolvedClass || klassTag == JVM_CONSTANT.UnresolvedClassInError : klassTag;
716 // fall through
717 case Class:
718 case UnresolvedClass:
719 case UnresolvedClassInError:
720 final HotSpotResolvedObjectTypeImpl type = compilerToVM().resolveTypeInPool(this, index);
721 Class<?> klass = type.mirror();
722 if (!klass.isPrimitive() && !klass.isArray()) {
723 UNSAFE.ensureClassInitialized(klass);
724 }
725 if (tag == JVM_CONSTANT.MethodRef) {
726 if (Bytecodes.isInvokeHandleAlias(opcode) && isSignaturePolymorphicHolder(type)) {
727 final int methodRefCacheIndex = rawIndexToConstantPoolCacheIndex(cpi, opcode);
728 assert checkTag(compilerToVM().constantPoolRemapInstructionOperandFromCache(this, methodRefCacheIndex), JVM_CONSTANT.MethodRef);
729 compilerToVM().resolveInvokeHandleInPool(this, methodRefCacheIndex);
730 }
731 }
732
733 break;
734 case InvokeDynamic:
735 if (isInvokedynamicIndex(cpi)) {
736 compilerToVM().resolveInvokeDynamicInPool(this, cpi);
737 }
738 break;
739 default:
740 // nothing
741 break;
742 }
743
|
1 /*
2 * Copyright (c) 2011, 2018, 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 */
646 /*
647 * Converts a raw index from the bytecodes to a constant pool index
648 * (not a cache index).
649 *
650 * @param rawIndex index from the bytecode
651 * @param opcode bytecode to convert the index for
652 * @return constant pool index
653 */
654 public int rawIndexToConstantPoolIndex(int index, int opcode) {
655 if (isInvokedynamicIndex(index)) {
656 assert opcode == Bytecodes.INVOKEDYNAMIC;
657 index = decodeInvokedynamicIndex(index) + config().constantPoolCpCacheIndexTag;
658 } else {
659 assert opcode != Bytecodes.INVOKEDYNAMIC;
660 index = rawIndexToConstantPoolCacheIndex(index, opcode);
661 }
662 return compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index);
663 }
664
665 @Override
666 public void loadReferencedType(int cpi, int opcode) {
667 loadReferencedType(cpi, opcode, true /* initialize */);
668 }
669
670 @SuppressWarnings("fallthrough")
671 public void loadReferencedType(int cpi, int opcode, boolean initialize) {
672 int index;
673 switch (opcode) {
674 case Bytecodes.CHECKCAST:
675 case Bytecodes.INSTANCEOF:
676 case Bytecodes.NEW:
677 case Bytecodes.ANEWARRAY:
678 case Bytecodes.MULTIANEWARRAY:
679 case Bytecodes.LDC:
680 case Bytecodes.LDC_W:
681 case Bytecodes.LDC2_W:
682 index = cpi;
683 break;
684 case Bytecodes.INVOKEDYNAMIC: {
685 // invokedynamic instructions point to a constant pool cache entry.
686 index = decodeConstantPoolCacheIndex(cpi) + config().constantPoolCpCacheIndexTag;
687 index = compilerToVM().constantPoolRemapInstructionOperandFromCache(this, index);
688 break;
689 }
690 case Bytecodes.GETSTATIC:
691 case Bytecodes.PUTSTATIC:
705 }
706
707 final JVM_CONSTANT tag = getTagAt(index);
708 if (tag == null) {
709 assert getTagAt(index - 1) == JVM_CONSTANT.Double || getTagAt(index - 1) == JVM_CONSTANT.Long;
710 return;
711 }
712 switch (tag) {
713 case MethodRef:
714 case Fieldref:
715 case InterfaceMethodref:
716 index = getUncachedKlassRefIndexAt(index);
717 // Read the tag only once because it could change between multiple reads.
718 final JVM_CONSTANT klassTag = getTagAt(index);
719 assert klassTag == JVM_CONSTANT.Class || klassTag == JVM_CONSTANT.UnresolvedClass || klassTag == JVM_CONSTANT.UnresolvedClassInError : klassTag;
720 // fall through
721 case Class:
722 case UnresolvedClass:
723 case UnresolvedClassInError:
724 final HotSpotResolvedObjectTypeImpl type = compilerToVM().resolveTypeInPool(this, index);
725 if (initialize) {
726 Class<?> klass = type.mirror();
727 if (!klass.isPrimitive() && !klass.isArray()) {
728 UNSAFE.ensureClassInitialized(klass);
729 }
730 }
731 if (tag == JVM_CONSTANT.MethodRef) {
732 if (Bytecodes.isInvokeHandleAlias(opcode) && isSignaturePolymorphicHolder(type)) {
733 final int methodRefCacheIndex = rawIndexToConstantPoolCacheIndex(cpi, opcode);
734 assert checkTag(compilerToVM().constantPoolRemapInstructionOperandFromCache(this, methodRefCacheIndex), JVM_CONSTANT.MethodRef);
735 compilerToVM().resolveInvokeHandleInPool(this, methodRefCacheIndex);
736 }
737 }
738
739 break;
740 case InvokeDynamic:
741 if (isInvokedynamicIndex(cpi)) {
742 compilerToVM().resolveInvokeDynamicInPool(this, cpi);
743 }
744 break;
745 default:
746 // nothing
747 break;
748 }
749
|