Search in sources :

Example 1 with RuntimeMethodInfo

use of com.oracle.svm.core.code.RuntimeMethodInfo in project graal by oracle.

the class InstalledCodeBuilder method installOperation.

@SuppressWarnings("try")
private void installOperation() {
    AMD64InstructionPatcher patcher = new AMD64InstructionPatcher(compilation);
    patchData(patcher);
    int updatedCodeSize = patchCalls(patcher);
    assert updatedCodeSize <= constantsOffset;
    // Store the compiled code
    for (int index = 0; index < updatedCodeSize; index++) {
        code.writeByte(index, compiledBytes[index]);
    }
    /* Primitive constants are written directly to the code memory. */
    ByteBuffer constantsBuffer = SubstrateUtil.wrapAsByteBuffer(code.add(constantsOffset), compilation.getDataSection().getSectionSize());
    /*
         * Object constants are stored in an Object[] array first, because we have to be careful
         * that they are always exposed as roots to the GC.
         */
    ObjectConstantsHolder objectConstants = new ObjectConstantsHolder(compilation);
    compilation.getDataSection().buildDataSection(constantsBuffer, (position, constant) -> {
        objectConstants.add(position, KnownIntrinsics.convertUnknownValue(SubstrateObjectConstant.asObject(constant), Object.class));
    });
    // Open the PinnedAllocator for the meta-information.
    metaInfoAllocator.open();
    try {
        runtimeMethodInfo = metaInfoAllocator.newInstance(RuntimeMethodInfo.class);
        constantsWalker = metaInfoAllocator.newInstance(ConstantsWalker.class);
        ReferenceMapEncoder encoder = new ReferenceMapEncoder();
        encoder.add(objectConstants.referenceMap);
        constantsWalker.referenceMapEncoding = encoder.encodeAll(metaInfoAllocator);
        constantsWalker.referenceMapIndex = encoder.lookupEncoding(objectConstants.referenceMap);
        constantsWalker.constantsAddr = code.add(constantsOffset);
        constantsWalker.constantsSize = compilation.getDataSection().getSectionSize();
        Heap.getHeap().getGC().registerObjectReferenceWalker(constantsWalker);
        /*
             * We now have the constantsWalker initialized and registered, but it is still inactive.
             * Writing the actual object constants to the code memory needs to be atomic regarding
             * to GC. After everything is written, we activate the constantsWalker.
             */
        try (NoAllocationVerifier verifier = NoAllocationVerifier.factory("InstalledCodeBuilder.install")) {
            writeObjectConstantsToCode(objectConstants);
        }
        createCodeChunkInfos();
        InstalledCodeObserver.InstalledCodeObserverHandle[] observerHandles = InstalledCodeObserverSupport.installObservers(codeObservers, metaInfoAllocator);
        runtimeMethodInfo.setData((CodePointer) code, WordFactory.unsigned(codeSize), installedCode, constantsWalker, metaInfoAllocator, observerHandles);
    } finally {
        metaInfoAllocator.close();
    }
    Throwable[] errorBox = { null };
    VMOperation.enqueueBlockingSafepoint("Install code", () -> {
        try {
            CodeInfoTable.getRuntimeCodeCache().addMethod(runtimeMethodInfo);
            /*
                 * This call makes the new code visible, i.e., other threads can start executing it
                 * immediately. So all metadata must be registered at this point.
                 */
            installedCode.setAddress(code.rawValue(), method);
        } catch (Throwable e) {
            errorBox[0] = e;
        }
    });
    if (errorBox[0] != null) {
        throw rethrow(errorBox[0]);
    }
    compilation = null;
}
Also used : RuntimeMethodInfo(com.oracle.svm.core.code.RuntimeMethodInfo) ByteBuffer(java.nio.ByteBuffer) Infopoint(jdk.vm.ci.code.site.Infopoint) ReferenceMapEncoder(com.oracle.svm.core.heap.ReferenceMapEncoder) AMD64InstructionPatcher(com.oracle.svm.core.graal.code.amd64.AMD64InstructionPatcher) NoAllocationVerifier(com.oracle.svm.core.heap.NoAllocationVerifier)

Aggregations

RuntimeMethodInfo (com.oracle.svm.core.code.RuntimeMethodInfo)1 AMD64InstructionPatcher (com.oracle.svm.core.graal.code.amd64.AMD64InstructionPatcher)1 NoAllocationVerifier (com.oracle.svm.core.heap.NoAllocationVerifier)1 ReferenceMapEncoder (com.oracle.svm.core.heap.ReferenceMapEncoder)1 ByteBuffer (java.nio.ByteBuffer)1 Infopoint (jdk.vm.ci.code.site.Infopoint)1