當前位置: 首頁>>代碼示例>>Java>>正文


Java ConstantPool類代碼示例

本文整理匯總了Java中jdk.vm.ci.meta.ConstantPool的典型用法代碼示例。如果您正苦於以下問題:Java ConstantPool類的具體用法?Java ConstantPool怎麽用?Java ConstantPool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConstantPool類屬於jdk.vm.ci.meta包,在下文中一共展示了ConstantPool類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validate

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
public static void validate(ConstantPool constantPoolCTVM,
                            ConstantTypes cpType,
                            DummyClasses dummyClass,
                            int i) {
    TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, i);
    if (entry == null) {
        return;
    }
    HotSpotResolvedObjectType typeToVerify = CompilerToVMHelper.resolveTypeInPool(constantPoolCTVM, i);
    String classNameToRefer = entry.klass;
    String outputToVerify = typeToVerify.toString();
    if (!outputToVerify.contains(classNameToRefer)) {
        String msg = String.format("Wrong class accessed by constant"
                                           + " pool index %d: %s, but should be %s",
                                   i,
                                   outputToVerify,
                                   classNameToRefer);
        throw new AssertionError(msg);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ResolveTypeInPoolTest.java

示例2: validate

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validate(ConstantPool constantPoolCTVM,
                             ConstantTypes cpType,
                             DummyClasses dummyClass,
                             int cpi) {
    TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
    if (entry == null) {
        return;
    }
    int index = cpi;
    String cached = "";
    int cpci = dummyClass.getCPCacheIndex(cpi);
    if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
        index = cpci;
        cached = "cached ";
    }
    String sigToVerify = CompilerToVMHelper.lookupSignatureInPool(constantPoolCTVM, index);
    String sigToRefer = entry.type;
    String msg = String.format("Wrong signature accessed by %sconstant pool index %d",
                               cached,
                               index);
    Asserts.assertEQ(sigToVerify, sigToRefer, msg);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:LookupSignatureInPoolTest.java

示例3: validateMethodHandle

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validateMethodHandle(ConstantPool constantPoolCTVM,
                                         ConstantTypes cpType,
                                         DummyClasses dummyClass,
                                         int index) {
    Object constantInPool = CompilerToVMHelper.resolveConstantInPool(constantPoolCTVM, index);
    String msg = String.format("%s for index %d", NOT_NULL_MSG, index);
    Asserts.assertNotNull(constantInPool, msg);
    if (!(constantInPool instanceof MethodHandle)) {
        msg = String.format("Wrong constant pool entry accessed by index"
                                    + " %d: %s, but should be subclass of %s",
                            index,
                            constantInPool.getClass(),
                            MethodHandle.class.getName());
        throw new AssertionError(msg);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ResolveConstantInPoolTest.java

示例4: validate

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validate(ConstantPool constantPoolCTVM,
                             ConstantTypes cpType,
                             DummyClasses dummyClass,
                             int cpi) {
    TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
    if (entry == null) {
        return;
    }
    int index = cpi;
    String cached = "";
    int cpci = dummyClass.getCPCacheIndex(cpi);
    if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
        index = cpci;
        cached = "cached ";
    }
    int indexToVerify = CompilerToVMHelper.lookupNameAndTypeRefIndexInPool(constantPoolCTVM, index);
    int indexToRefer = dummyClass.constantPoolSS.getNameAndTypeRefIndexAt(cpi);
    String msg = String.format("Wrong nameAndType index returned by lookupNameAndTypeRefIndexInPool"
                                       + " method applied to %sconstant pool index %d",
                               cached,
                               index);
    Asserts.assertEQ(indexToRefer, indexToVerify, msg);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:LookupNameAndTypeRefIndexInPoolTest.java

示例5: getResolvedJavaType

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
@Override
HotSpotResolvedObjectType getResolvedJavaType() {
    ConstantPool cpInst;
    try {
        cpInst = CompilerToVMHelper.getConstantPool(null,
                getPtrToKlass());
        // jdk.vm.ci.hotspot.HotSpotConstantPool.metaspaceConstantPool
        Field field = cpInst.getClass()
                .getDeclaredField("metaspaceConstantPool");
        field.setAccessible(true);
        field.set(cpInst, getPtrToKlass());
    } catch (ReflectiveOperationException e) {
        throw new Error("TESTBUG : " + e, e);
    }
    return CompilerToVMHelper.getResolvedJavaType(cpInst,
            0L, COMPRESSED);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:GetResolvedJavaTypeTest.java

示例6: validateString

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validateString(ConstantPool constantPoolCTVM,
                                   ConstantTypes cpType,
                                   DummyClasses dummyClass,
                                   int cpi) {
    TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
    if (entry == null) {
        return;
    }
    int index = cpi;
    String cached = "";
    int cpci = dummyClass.getCPCacheIndex(cpi);
    if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
        index = cpci;
        cached = "cached ";
    }
    Object constantInPool = CompilerToVMHelper.resolvePossiblyCachedConstantInPool(constantPoolCTVM, index);
    String stringToVerify = (String) constantInPool;
    String stringToRefer = entry.name;
    if (stringToRefer.equals("") && cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
        stringToRefer = null; // tested method returns null for cached empty strings
    }
    String msg = String.format("Wrong string accessed by %sconstant pool index %d", cached, index);
    Asserts.assertEQ(stringToRefer, stringToVerify, msg);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ResolvePossiblyCachedConstantInPoolTest.java

示例7: getSymbols

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private List<String> getSymbols(HotSpotResolvedJavaMethod
        metaspaceMethod) throws ReflectiveOperationException {
    List<String> symbols = new ArrayList<>();
    ConstantPool pool = metaspaceMethod.getConstantPool();
    long length = pool.length();
    // jvms-4.1: The constant_pool table is indexed from 1 ...
    for (int i = 1; i < length; i++) {
        if (getTag(pool, i) == CONSTANT_POOL_UTF8_TAG) {
            long entryPointer;
            Method getEntryAt = pool.getClass()
                    .getDeclaredMethod("getEntryAt", int.class);
            getEntryAt.setAccessible(true);
            entryPointer = (Long) getEntryAt.invoke(pool, i);
            String symbol = CompilerToVMHelper.getSymbol(entryPointer);
            symbols.add(symbol);
        }
    }
    return symbols;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:GetSymbolTest.java

示例8: validate

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validate(ConstantPool constantPoolCTVM,
                             ConstantTypes cpType,
                             DummyClasses dummyClass,
                             int cpi) {
    TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
    if (entry == null) {
        return;
    }
    int index = cpi;
    String cached = "";
    int cpci = dummyClass.getCPCacheIndex(cpi);
    if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
        index = cpci;
        cached = "cached ";
    }
    int indexToVerify = CompilerToVMHelper.lookupKlassRefIndexInPool(constantPoolCTVM, index);
    int indexToRefer = dummyClass.constantPoolSS.getClassRefIndexAt(cpi);
    String msg = String.format("Wrong class index returned by lookupKlassRefIndexInPool method "
                                       + "applied to %sconstant pool index %d",
                               cached,
                               index);
    Asserts.assertEQ(indexToRefer, indexToVerify, msg);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:LookupKlassRefIndexInPoolTest.java

示例9: validate

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validate(ConstantPool constantPoolCTVM,
                             ConstantTypes cpType,
                             DummyClasses dummyClass,
                             int cpi) {
    TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
    if (entry == null) {
        return;
    }
    int index = cpi;
    String cached = "";
    int cpci = dummyClass.getCPCacheIndex(cpi);
    if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
        index = cpci;
        cached = "cached ";
    }
    String nameToVerify = CompilerToVMHelper.lookupNameInPool(constantPoolCTVM, index);
    String nameToRefer = entry.name;
    String msg = String.format("Wrong name accessed by %sconstant pool index %d", cached, index);
    Asserts.assertEQ(nameToVerify, nameToRefer, msg);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:LookupNameInPoolTest.java

示例10: getConstantPool

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
@Override
ConstantPool getConstantPool() {
    HotSpotResolvedJavaMethod methodInstance
            = CompilerToVMHelper.getResolvedJavaMethodAtSlot(
                    TEST_CLASS, 0);
    Field field;
    try {
        // jdk.vm.ci.hotspot.HotSpotResolvedJavaMethodImpl.metaspaceMethod
        field = methodInstance.getClass()
                .getDeclaredField("metaspaceMethod");
        field.setAccessible(true);
        field.set(methodInstance, getPtrToCpAddress());
    } catch (ReflectiveOperationException e) {
        throw new Error("TESTBUG : " + e, e);
    }

    return CompilerToVMHelper.getConstantPool(methodInstance, 0L);
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:19,代碼來源:GetConstantPoolTest.java

示例11: test

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
public void test(TestCase testCase) {
    System.out.println(testCase.name());
    ConstantPool cp = testCase.getConstantPool();
    String cpStringRep = cp.toString();
    String cpClassSimpleName
            = CompilerToVMHelper.HotSpotConstantPoolClass().getSimpleName();
    if (!cpStringRep.contains(cpClassSimpleName)
            || !cpStringRep.contains(TEST_CLASS.getName())) {
        String msg = String.format("%s : "
                + " Constant pool is not valid."
                + " String representation should contain \"%s\" and \"%s\"",
                testCase.name(), cpClassSimpleName,
                TEST_CLASS.getName());
        throw new AssertionError(msg);
    }
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:17,代碼來源:GetConstantPoolTest.java

示例12: disassemble

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
/**
 * Disassembles {@code code} in a {@code javap}-like format.
 */
public String disassemble(Bytecode code, int startBci, int endBci) {
    if (code.getCode() == null) {
        return null;
    }
    ResolvedJavaMethod method = code.getMethod();
    ConstantPool cp = code.getConstantPool();
    BytecodeStream stream = new BytecodeStream(code.getCode());
    StringBuilder buf = new StringBuilder();
    int opcode = stream.currentBC();
    try {
        while (opcode != Bytecodes.END) {
            int bci = stream.currentBCI();
            if (bci >= startBci && bci <= endBci) {
                String mnemonic = Bytecodes.nameOf(opcode);
                buf.append(String.format("%4d: %-14s", bci, mnemonic));
                if (stream.nextBCI() > bci + 1) {
                    decodeOperand(buf, stream, cp, method, bci, opcode);
                }
                if (newLine) {
                    buf.append(String.format("%n"));
                }
            }
            stream.next();
            opcode = stream.currentBC();
        }
    } catch (Throwable e) {
        throw new RuntimeException(String.format("Error disassembling %s%nPartial disassembly:%n%s", method.format("%H.%n(%p)"), buf.toString()), e);
    }
    return buf.toString();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:BytecodeDisassembler.java

示例13: lookupMethodOrNull

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
static ResolvedJavaMethod lookupMethodOrNull(ConstantPool cp, int cpi, int opcode) {
    try {
        return lookupMethod(cp, cpi, opcode);
    } catch (NoSuchMethodError e) {
        // A method hidden to reflection
        return null;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:ClassfileBytecodeProviderTest.java

示例14: validateMethodType

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
private static void validateMethodType(ConstantPool constantPoolCTVM,
                                       ConstantTypes cpType,
                                       DummyClasses dummyClass,
                                       int index) {
    Object constantInPool = CompilerToVMHelper.resolveConstantInPool(constantPoolCTVM, index);
    String msg = String.format("%s for index %d", NOT_NULL_MSG, index);
    Asserts.assertNotNull(constantInPool, msg);
    Class mtToVerify = constantInPool.getClass();
    Class mtToRefer = MethodType.class;
    msg = String.format("Wrong method type class accessed by"
                                + " constant pool index %d",
                        index);
    Asserts.assertEQ(mtToRefer, mtToVerify, msg);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ResolveConstantInPoolTest.java

示例15: getConstantPoolTest

import jdk.vm.ci.meta.ConstantPool; //導入依賴的package包/類
@Test
public void getConstantPoolTest() {
    for (Map.Entry<Method, ResolvedJavaMethod> e : methods.entrySet()) {
        ResolvedJavaMethod m = e.getValue();
        ConstantPool cp = m.getConstantPool();
        assertTrue(cp.length() > 0);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:TestResolvedJavaMethod.java


注:本文中的jdk.vm.ci.meta.ConstantPool類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。