Search in sources :

Example 6 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class ReplaceConstantNodesPhase method handleHotSpotObjectConstant.

/**
 * Replace an object constant with an indirect load {@link ResolveConstantNode}. Currently we
 * support only strings.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotObjectConstant} that needs
 *            resolution.
 */
private static void handleHotSpotObjectConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotObjectConstant constant = (HotSpotObjectConstant) node.asJavaConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) constant.getType();
    if (type.mirror().equals(String.class)) {
        assert !constant.isCompressed() : "No support for replacing compressed oop constants";
        FixedWithNextNode replacement = graph.add(new ResolveConstantNode(node));
        insertReplacement(graph, stateMapper, node, replacement);
        node.replaceAtUsages(replacement, n -> !(n instanceof ResolveConstantNode));
    } else {
        throw new GraalError("Unsupported object constant type: " + type);
    }
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Example 7 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class HotSpotHostForeignCallsProvider method initialize.

public void initialize(HotSpotProviders providers, OptionValues options) {
    GraalHotSpotVMConfig c = runtime.getVMConfig();
    registerForeignCall(DEOPTIMIZATION_HANDLER, c.handleDeoptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(UNCOMMON_TRAP_HANDLER, c.uncommonTrapStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(IC_MISS_HANDLER, c.inlineCacheMissStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(JAVA_TIME_MILLIS, c.javaTimeMillisAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(JAVA_TIME_NANOS, c.javaTimeNanosAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(SIN.foreignCallDescriptor, c.arithmeticSinAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(COS.foreignCallDescriptor, c.arithmeticCosAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(TAN.foreignCallDescriptor, c.arithmeticTanAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(EXP.foreignCallDescriptor, c.arithmeticExpAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(LOG.foreignCallDescriptor, c.arithmeticLogAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(LOG10.foreignCallDescriptor, c.arithmeticLog10Address, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(POW.foreignCallDescriptor, c.arithmeticPowAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(ARITHMETIC_FREM, c.fremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(ARITHMETIC_DREM, c.dremAddress, NativeCall, DESTROYS_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(LOAD_AND_CLEAR_EXCEPTION, c.loadAndClearExceptionAddress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, any());
    registerForeignCall(EXCEPTION_HANDLER_FOR_PC, c.exceptionHandlerForPcAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
    registerForeignCall(EXCEPTION_HANDLER_FOR_RETURN_ADDRESS, c.exceptionHandlerForReturnAddressAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
    registerForeignCall(NEW_ARRAY_C, c.newArrayAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
    registerForeignCall(NEW_INSTANCE_C, c.newInstanceAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, any());
    CreateExceptionStub.registerForeignCalls(c, this);
    /*
         * This message call is registered twice, where the second one must only be used for calls
         * that do not return, i.e., that exit the VM.
         */
    registerForeignCall(VM_MESSAGE_C, c.vmMessageAddress, NativeCall, DESTROYS_REGISTERS, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
    registerForeignCall(ASSERTION_VM_MESSAGE_C, c.vmMessageAddress, NativeCall, PRESERVES_REGISTERS, LEAF, REEXECUTABLE, NO_LOCATIONS);
    link(new NewInstanceStub(options, providers, registerStubCall(NEW_INSTANCE, REEXECUTABLE, SAFEPOINT, TLAB_TOP_LOCATION, TLAB_END_LOCATION)));
    link(new NewArrayStub(options, providers, registerStubCall(NEW_ARRAY, REEXECUTABLE, SAFEPOINT, TLAB_TOP_LOCATION, TLAB_END_LOCATION)));
    link(new ExceptionHandlerStub(options, providers, foreignCalls.get(EXCEPTION_HANDLER)));
    link(new UnwindExceptionToCallerStub(options, providers, registerStubCall(UNWIND_EXCEPTION_TO_CALLER, NOT_REEXECUTABLE, SAFEPOINT, any())));
    link(new VerifyOopStub(options, providers, registerStubCall(VERIFY_OOP, REEXECUTABLE, LEAF_NOFP, NO_LOCATIONS)));
    link(new ArrayStoreExceptionStub(options, providers, registerStubCall(CREATE_ARRAY_STORE_EXCEPTION, REEXECUTABLE, SAFEPOINT, any())));
    link(new ClassCastExceptionStub(options, providers, registerStubCall(CREATE_CLASS_CAST_EXCEPTION, REEXECUTABLE, SAFEPOINT, any())));
    link(new NullPointerExceptionStub(options, providers, registerStubCall(CREATE_NULL_POINTER_EXCEPTION, REEXECUTABLE, SAFEPOINT, any())));
    link(new OutOfBoundsExceptionStub(options, providers, registerStubCall(CREATE_OUT_OF_BOUNDS_EXCEPTION, REEXECUTABLE, SAFEPOINT, any())));
    linkForeignCall(options, providers, IDENTITY_HASHCODE, c.identityHashCodeAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, MARK_WORD_LOCATION);
    linkForeignCall(options, providers, REGISTER_FINALIZER, c.registerFinalizerAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any());
    linkForeignCall(options, providers, MONITORENTER, c.monitorenterAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any());
    linkForeignCall(options, providers, MONITOREXIT, c.monitorexitAddress, PREPEND_THREAD, STACK_INSPECTABLE_LEAF, NOT_REEXECUTABLE, any());
    linkForeignCall(options, providers, NEW_MULTI_ARRAY, c.newMultiArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
    linkForeignCall(options, providers, DYNAMIC_NEW_ARRAY, c.dynamicNewArrayAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE);
    linkForeignCall(options, providers, DYNAMIC_NEW_INSTANCE, c.dynamicNewInstanceAddress, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE);
    linkForeignCall(options, providers, LOG_PRINTF, c.logPrintfAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, LOG_OBJECT, c.logObjectAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, LOG_PRIMITIVE, c.logPrimitiveAddress, PREPEND_THREAD, LEAF, REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, VM_ERROR, c.vmErrorAddress, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, OSR_MIGRATION_END, c.osrMigrationEndAddress, DONT_PREPEND_THREAD, LEAF_NOFP, NOT_REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, G1WBPRECALL, c.writeBarrierPreAddress, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, G1WBPOSTCALL, c.writeBarrierPostAddress, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    linkForeignCall(options, providers, VALIDATE_OBJECT, c.validateObject, PREPEND_THREAD, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
    if (GeneratePIC.getValue(options)) {
        registerForeignCall(WRONG_METHOD_HANDLER, c.handleWrongMethodStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, REEXECUTABLE, NO_LOCATIONS);
        CompilerRuntimeHotSpotVMConfig cr = new CompilerRuntimeHotSpotVMConfig(HotSpotJVMCIRuntime.runtime().getConfigStore());
        linkForeignCall(options, providers, RESOLVE_STRING_BY_SYMBOL, cr.resolveStringBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, TLAB_TOP_LOCATION, TLAB_END_LOCATION);
        linkForeignCall(options, providers, RESOLVE_DYNAMIC_INVOKE, cr.resolveDynamicInvoke, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
        linkForeignCall(options, providers, RESOLVE_KLASS_BY_SYMBOL, cr.resolveKlassBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
        linkForeignCall(options, providers, RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, cr.resolveMethodBySymbolAndLoadCounters, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
        linkForeignCall(options, providers, INITIALIZE_KLASS_BY_SYMBOL, cr.initializeKlassBySymbol, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
        linkForeignCall(options, providers, INVOCATION_EVENT, cr.invocationEvent, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
        linkForeignCall(options, providers, BACKEDGE_EVENT, cr.backedgeEvent, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, NO_LOCATIONS);
    }
    // Cannot be a leaf as VM acquires Thread_lock which requires thread_in_vm state
    linkForeignCall(options, providers, THREAD_IS_INTERRUPTED, c.threadIsInterruptedAddress, PREPEND_THREAD, SAFEPOINT, NOT_REEXECUTABLE, any());
    linkForeignCall(options, providers, TEST_DEOPTIMIZE_CALL_INT, c.testDeoptimizeCallInt, PREPEND_THREAD, SAFEPOINT, REEXECUTABLE, any());
    registerArrayCopy(JavaKind.Byte, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Boolean, c.jbyteArraycopy, c.jbyteAlignedArraycopy, c.jbyteDisjointArraycopy, c.jbyteAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Char, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Short, c.jshortArraycopy, c.jshortAlignedArraycopy, c.jshortDisjointArraycopy, c.jshortAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Int, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Float, c.jintArraycopy, c.jintAlignedArraycopy, c.jintDisjointArraycopy, c.jintAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Long, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Double, c.jlongArraycopy, c.jlongAlignedArraycopy, c.jlongDisjointArraycopy, c.jlongAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Object, c.oopArraycopy, c.oopAlignedArraycopy, c.oopDisjointArraycopy, c.oopAlignedDisjointArraycopy);
    registerArrayCopy(JavaKind.Object, c.oopArraycopyUninit, c.oopAlignedArraycopyUninit, c.oopDisjointArraycopyUninit, c.oopAlignedDisjointArraycopyUninit, true);
    registerCheckcastArraycopyDescriptor(true, c.checkcastArraycopyUninit);
    registerCheckcastArraycopyDescriptor(false, c.checkcastArraycopy);
    registerForeignCall(GENERIC_ARRAYCOPY, c.genericArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
    registerForeignCall(UNSAFE_ARRAYCOPY, c.unsafeArraycopy, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
    if (c.useMultiplyToLenIntrinsic()) {
        registerForeignCall(MULTIPLY_TO_LEN, c.multiplyToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
    }
    if (c.useSHA1Intrinsics()) {
        registerForeignCall(SHA_IMPL_COMPRESS, c.sha1ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
    }
    if (c.useSHA256Intrinsics()) {
        registerForeignCall(SHA2_IMPL_COMPRESS, c.sha256ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
    }
    if (c.useSHA512Intrinsics()) {
        registerForeignCall(SHA5_IMPL_COMPRESS, c.sha512ImplCompress, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.any());
    }
    if (c.useMulAddIntrinsic()) {
        registerForeignCall(MUL_ADD, c.mulAdd, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
    }
    if (c.useMontgomeryMultiplyIntrinsic()) {
        registerForeignCall(MONTGOMERY_MULTIPLY, c.montgomeryMultiply, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
    }
    if (c.useMontgomerySquareIntrinsic()) {
        registerForeignCall(MONTGOMERY_SQUARE, c.montgomerySquare, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
    }
    if (c.useSquareToLenIntrinsic()) {
        registerForeignCall(SQUARE_TO_LEN, c.squareToLen, NativeCall, DESTROYS_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Int));
    }
    if (c.useAESIntrinsics) {
        /*
             * When the java.ext.dirs property is modified then the crypto classes might not be
             * found. If that's the case we ignore the ClassNotFoundException and continue since we
             * cannot replace a non-existing method anyway.
             */
        try {
            // These stubs do callee saving
            registerForeignCall(ENCRYPT_BLOCK, c.aescryptEncryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
            registerForeignCall(DECRYPT_BLOCK, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
            registerForeignCall(DECRYPT_BLOCK_WITH_ORIGINAL_KEY, c.aescryptDecryptBlockStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
        } catch (GraalError e) {
            if (!(e.getCause() instanceof ClassNotFoundException)) {
                throw e;
            }
        }
        try {
            // These stubs do callee saving
            registerForeignCall(ENCRYPT, c.cipherBlockChainingEncryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
            registerForeignCall(DECRYPT, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
            registerForeignCall(DECRYPT_WITH_ORIGINAL_KEY, c.cipherBlockChainingDecryptAESCryptStub, NativeCall, PRESERVES_REGISTERS, LEAF_NOFP, NOT_REEXECUTABLE, NamedLocationIdentity.getArrayLocation(JavaKind.Byte));
        } catch (GraalError e) {
            if (!(e.getCause() instanceof ClassNotFoundException)) {
                throw e;
            }
        }
    }
}
Also used : NewArrayStub(org.graalvm.compiler.hotspot.stubs.NewArrayStub) OutOfBoundsExceptionStub(org.graalvm.compiler.hotspot.stubs.OutOfBoundsExceptionStub) ArrayStoreExceptionStub(org.graalvm.compiler.hotspot.stubs.ArrayStoreExceptionStub) VerifyOopStub(org.graalvm.compiler.hotspot.stubs.VerifyOopStub) CompilerRuntimeHotSpotVMConfig(org.graalvm.compiler.hotspot.CompilerRuntimeHotSpotVMConfig) GraalError(org.graalvm.compiler.debug.GraalError) NewInstanceStub(org.graalvm.compiler.hotspot.stubs.NewInstanceStub) NullPointerExceptionStub(org.graalvm.compiler.hotspot.stubs.NullPointerExceptionStub) ExceptionHandlerStub(org.graalvm.compiler.hotspot.stubs.ExceptionHandlerStub) UnwindExceptionToCallerStub(org.graalvm.compiler.hotspot.stubs.UnwindExceptionToCallerStub) ClassCastExceptionStub(org.graalvm.compiler.hotspot.stubs.ClassCastExceptionStub) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig)

Example 8 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class HotSpotDataBuilder method createDataItem.

@Override
public Data createDataItem(Constant constant) {
    if (JavaConstant.isNull(constant)) {
        boolean compressed = COMPRESSED_NULL.equals(constant);
        int size = compressed ? 4 : target.wordSize;
        return ZeroData.create(size, size);
    } else if (constant instanceof VMConstant) {
        VMConstant vmConstant = (VMConstant) constant;
        if (!(constant instanceof HotSpotConstant)) {
            throw new GraalError(String.valueOf(constant));
        }
        HotSpotConstant c = (HotSpotConstant) vmConstant;
        int size = c.isCompressed() ? 4 : target.wordSize;
        return new Data(size, size) {

            @Override
            protected void emit(ByteBuffer buffer, Patches patches) {
                int position = buffer.position();
                if (getSize() == Integer.BYTES) {
                    buffer.putInt(0xDEADDEAD);
                } else {
                    buffer.putLong(0xDEADDEADDEADDEADL);
                }
                patches.registerPatch(position, vmConstant);
            }
        };
    } else if (constant instanceof SerializableConstant) {
        SerializableConstant s = (SerializableConstant) constant;
        return new SerializableData(s);
    } else {
        throw new GraalError(String.valueOf(constant));
    }
}
Also used : HotSpotConstant(jdk.vm.ci.hotspot.HotSpotConstant) GraalError(org.graalvm.compiler.debug.GraalError) VMConstant(jdk.vm.ci.meta.VMConstant) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) ZeroData(org.graalvm.compiler.code.DataSection.ZeroData) Data(org.graalvm.compiler.code.DataSection.Data) ByteBuffer(java.nio.ByteBuffer) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) Patches(org.graalvm.compiler.code.DataSection.Patches) SerializableConstant(jdk.vm.ci.meta.SerializableConstant)

Example 9 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class CompilerConfigurationFactory method selectFactory.

/**
 * Selects and instantiates a {@link CompilerConfigurationFactory}. The selection algorithm is
 * as follows: if {@code name} is non-null, then select the factory with the same name else if
 * {@code Options.CompilerConfiguration.getValue()} is non-null then select the factory whose
 * name matches the value else select the factory with the highest
 * {@link #autoSelectionPriority} value.
 *
 * @param name the name of the compiler configuration to select (optional)
 */
@SuppressWarnings("try")
public static CompilerConfigurationFactory selectFactory(String name, OptionValues options) {
    CompilerConfigurationFactory factory = null;
    try (InitTimer t = timer("CompilerConfigurationFactory.selectFactory")) {
        String value = name == null ? Options.CompilerConfiguration.getValue(options) : name;
        if ("help".equals(value)) {
            System.out.println("The available Graal compiler configurations are:");
            for (CompilerConfigurationFactory candidate : getAllCandidates()) {
                System.out.println("    " + candidate.name);
            }
            System.exit(0);
        } else if (value != null) {
            for (CompilerConfigurationFactory candidate : GraalServices.load(CompilerConfigurationFactory.class)) {
                if (candidate.name.equals(value)) {
                    factory = candidate;
                    break;
                }
            }
            if (factory == null) {
                throw new GraalError("Graal compiler configuration '%s' not found. Available configurations are: %s", value, getAllCandidates().stream().map(c -> c.name).collect(Collectors.joining(", ")));
            }
        } else {
            List<CompilerConfigurationFactory> candidates = getAllCandidates();
            if (candidates.isEmpty()) {
                throw new GraalError("No %s providers found", CompilerConfigurationFactory.class.getName());
            }
            factory = candidates.get(0);
        }
    }
    ShowConfigurationLevel level = Options.ShowConfiguration.getValue(options);
    if (level != ShowConfigurationLevel.none) {
        switch(level) {
            case info:
                {
                    printConfigInfo(factory);
                    break;
                }
            case verbose:
                {
                    printConfigInfo(factory);
                    CompilerConfiguration config = factory.createCompilerConfiguration();
                    TTY.println("High tier: " + phaseNames(config.createHighTier(options)));
                    TTY.println("Mid tier: " + phaseNames(config.createMidTier(options)));
                    TTY.println("Low tier: " + phaseNames(config.createLowTier(options)));
                    TTY.println("Pre regalloc stage: " + phaseNames(config.createPreAllocationOptimizationStage(options)));
                    TTY.println("Regalloc stage: " + phaseNames(config.createAllocationStage(options)));
                    TTY.println("Post regalloc stage: " + phaseNames(config.createPostAllocationOptimizationStage(options)));
                    config.createAllocationStage(options);
                    break;
                }
        }
    }
    return factory;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) OptionType(org.graalvm.compiler.options.OptionType) TTY(org.graalvm.compiler.debug.TTY) URL(java.net.URL) OptionKey(org.graalvm.compiler.options.OptionKey) BasePhase(org.graalvm.compiler.phases.BasePhase) Collection(java.util.Collection) Architecture(jdk.vm.ci.code.Architecture) InitTimer.timer(jdk.vm.ci.common.InitTimer.timer) CompilerConfiguration(org.graalvm.compiler.phases.tiers.CompilerConfiguration) GraalServices(org.graalvm.compiler.serviceprovider.GraalServices) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) LIRPhase(org.graalvm.compiler.lir.phases.LIRPhase) List(java.util.List) EnumOptionKey(org.graalvm.compiler.options.EnumOptionKey) Option(org.graalvm.compiler.options.Option) EconomicMap(org.graalvm.collections.EconomicMap) LIRPhaseSuite(org.graalvm.compiler.lir.phases.LIRPhaseSuite) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraalError(org.graalvm.compiler.debug.GraalError) InitTimer(jdk.vm.ci.common.InitTimer) Collections(java.util.Collections) InitTimer(jdk.vm.ci.common.InitTimer) GraalError(org.graalvm.compiler.debug.GraalError) CompilerConfiguration(org.graalvm.compiler.phases.tiers.CompilerConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class BenchmarkCounters method initialize.

public static void initialize(final HotSpotJVMCIRuntime jvmciRuntime, OptionValues options) {
    final class BenchmarkCountersOutputStream extends CallbackOutputStream {

        private long startTime;

        private boolean running;

        private boolean waitingForEnd;

        private BenchmarkCountersOutputStream(PrintStream delegate, String start, String end) {
            super(delegate, new String[] { "\n", end, start });
        }

        @Override
        protected void patternFound(int index) {
            switch(index) {
                case 2:
                    startTime = System.nanoTime();
                    BenchmarkCounters.clear(jvmciRuntime.collectCounters());
                    running = true;
                    break;
                case 1:
                    if (running) {
                        waitingForEnd = true;
                    }
                    break;
                case 0:
                    if (waitingForEnd) {
                        waitingForEnd = false;
                        running = false;
                        BenchmarkCounters.dump(options, getPrintStream(options), (System.nanoTime() - startTime) / 1000000000d, jvmciRuntime.collectCounters(), 100);
                    }
                    break;
            }
        }
    }
    if (Options.BenchmarkDynamicCounters.getValue(options) != null) {
        String[] arguments = Options.BenchmarkDynamicCounters.getValue(options).split(",");
        if (arguments.length == 0 || (arguments.length % 3) != 0) {
            throw new GraalError("invalid arguments to BenchmarkDynamicCounters: (err|out),start,end,(err|out),start,end,... (~ matches multiple digits)");
        }
        for (int i = 0; i < arguments.length; i += 3) {
            if (arguments[i].equals("err")) {
                System.setErr(new PrintStream(new BenchmarkCountersOutputStream(System.err, arguments[i + 1], arguments[i + 2])));
            } else if (arguments[i].equals("out")) {
                System.setOut(new PrintStream(new BenchmarkCountersOutputStream(System.out, arguments[i + 1], arguments[i + 2])));
            } else {
                throw new GraalError("invalid arguments to BenchmarkDynamicCounters: err|out");
            }
        }
        enabled = true;
    }
    if (Options.GenericDynamicCounters.getValue(options)) {
        enabled = true;
    }
    if (Options.TimedDynamicCounters.getValue(options) > 0) {
        Thread thread = new Thread() {

            long lastTime = System.nanoTime();

            PrintStream out = getPrintStream(options);

            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(Options.TimedDynamicCounters.getValue(options));
                    } catch (InterruptedException e) {
                    }
                    long time = System.nanoTime();
                    dump(options, out, (time - lastTime) / 1000000000d, jvmciRuntime.collectCounters(), 10);
                    lastTime = time;
                }
            }
        };
        thread.setDaemon(true);
        thread.setPriority(Thread.MAX_PRIORITY);
        thread.start();
        enabled = true;
    }
    if (enabled) {
        clear(jvmciRuntime.collectCounters());
    }
}
Also used : PrintStream(java.io.PrintStream) GraalError(org.graalvm.compiler.debug.GraalError)

Aggregations

GraalError (org.graalvm.compiler.debug.GraalError)42 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 Indent (org.graalvm.compiler.debug.Indent)5 IOException (java.io.IOException)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 Node (org.graalvm.compiler.graph.Node)4 OptionValues (org.graalvm.compiler.options.OptionValues)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 ArrayList (java.util.ArrayList)3 CompilationResult (org.graalvm.compiler.code.CompilationResult)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 Invoke (org.graalvm.compiler.nodes.Invoke)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 InstalledCode (jdk.vm.ci.code.InstalledCode)2