Search in sources :

Example 1 with SuppressFBWarnings

use of org.graalvm.compiler.core.common.SuppressFBWarnings in project graal by oracle.

the class SubstrateCodeCacheProvider method installCode.

@Override
@SuppressFBWarnings(value = { "BC_UNCONFIRMED_CAST" }, justification = "We know what we are doing.")
public InstalledCode installCode(ResolvedJavaMethod method, CompiledCode compiledCode, InstalledCode predefinedInstalledCode, SpeculationLog log, boolean isDefault) {
    VMError.guarantee(!isDefault);
    SubstrateInstalledCode substrateInstalledCode;
    if (predefinedInstalledCode instanceof SubstrateInstalledCode.Access) {
        substrateInstalledCode = ((SubstrateInstalledCode.Access) predefinedInstalledCode).getSubstrateInstalledCode();
    } else {
        substrateInstalledCode = (SubstrateInstalledCode) predefinedInstalledCode;
    }
    CompilationResult compResult = ((SubstrateCompiledCode) compiledCode).getCompilationResult();
    InstalledCodeBuilder builder = new InstalledCodeBuilder((SharedRuntimeMethod) method, compResult, substrateInstalledCode, null);
    builder.install();
    return predefinedInstalledCode;
}
Also used : SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) SubstrateCompiledCode(com.oracle.svm.core.graal.code.SubstrateCompiledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) SuppressFBWarnings(org.graalvm.compiler.core.common.SuppressFBWarnings)

Example 2 with SuppressFBWarnings

use of org.graalvm.compiler.core.common.SuppressFBWarnings in project graal by oracle.

the class Target_java_util_concurrent_locks_ReentrantLock method wait.

/**
 * Implements {@link Object#wait}.
 */
@SuppressFBWarnings(value = { "WA_AWAIT_NOT_IN_LOOP" }, justification = "This method is a wait implementation.")
public void wait(Object obj, long timeoutMillis) throws InterruptedException {
    assert obj != null;
    /* Required checks on the arguments. */
    if (Thread.interrupted()) {
        throw new InterruptedException();
    }
    if (timeoutMillis < 0) {
        throw new IllegalArgumentException("Timeout is negative.");
    }
    if (!SubstrateOptions.MultiThreaded.getValue()) {
        /*
             * Single-threaded wait. There is no other thread that can interrupt it, so it is just
             * sleeping. It is questionable whether this implementation is useful, especially
             * waiting without a timeout. But it is the best thing we can do.
             */
        Thread.sleep(timeoutMillis == 0 ? Long.MAX_VALUE : timeoutMillis);
        return;
    }
    /*
         * Ensure that the current thread holds the lock. Required by the specification of
         * Object.wait, and also required for our implementation.
         */
    ReentrantLock lock = ensureLocked(obj);
    Condition condition = getOrCreateCondition(obj, lock, true);
    if (timeoutMillis == 0L) {
        condition.await();
    } else {
        condition.await(timeoutMillis, TimeUnit.MILLISECONDS);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) SuppressFBWarnings(org.graalvm.compiler.core.common.SuppressFBWarnings)

Example 3 with SuppressFBWarnings

use of org.graalvm.compiler.core.common.SuppressFBWarnings in project graal by oracle.

the class AnalysisUniverse method createType.

@SuppressFBWarnings(value = { "ES_COMPARING_STRINGS_WITH_EQ" }, justification = "Bug in findbugs")
private AnalysisType createType(ResolvedJavaType type, ResolvedJavaType hostType) {
    if (!hostVM.platformSupported(type)) {
        throw new UnsupportedFeatureException("type is not available in this platform: " + type.toJavaName(true));
    }
    if (sealed && !type.isArray()) {
        /*
             * We allow new array classes to be created at any time, since they do not affect the
             * closed world analysis.
             */
        throw AnalysisError.typeNotFound(type);
    }
    if (!type.isArray() && !type.isPrimitive()) {
        type.initialize();
    }
    /*
         * We do not want multiple threads to create the AnalysisType simultaneously, because we
         * want a unique id number per type. So claim the type first, and only when the claim
         * succeeds create the AnalysisType.
         */
    Object claim = Thread.currentThread().getName();
    retry: while (true) {
        Object result = types.putIfAbsent(type, claim);
        if (result instanceof AnalysisType) {
            return (AnalysisType) result;
        } else if (result != null) {
            /*
                 * Another thread installed a claim, wait until that thread publishes the
                 * AnalysisType.
                 */
            do {
                result = types.get(type);
                if (result == null) {
                    /*
                         * The other thread gave up, probably because of an exception. Re-try to
                         * create the type ourself. Probably we are going to fail and throw an
                         * exception too, but that is OK.
                         */
                    continue retry;
                } else if (result == claim) {
                    /*
                         * We are waiting for a type that we have claimed ourselves => deadlock.
                         */
                    throw JVMCIError.shouldNotReachHere("Deadlock creating new types");
                }
            } while (!(result instanceof AnalysisType));
            return (AnalysisType) result;
        } else {
            break retry;
        }
    }
    try {
        JavaKind storageKind = getStorageKind(type, originalMetaAccess, getTarget());
        AnalysisType newValue = new AnalysisType(this, type, storageKind, objectClass);
        hostVM.registerType(newValue, hostType);
        synchronized (this) {
            /*
                 * Synchronize modifications of typesById, so that we do not lose array stores in
                 * one thread that run concurrently with Arrays.copyOf in another thread. This is
                 * the only code that writes to typesById. Reads from typesById in other parts do
                 * not need synchronization because typesById is a volatile field, i.e., reads
                 * always pick up the latest and longest array; and we never publish a type before
                 * it is registered in typesById, i.e., before the array has the appropriate length.
                 */
            if (newValue.getId() >= typesById.length) {
                typesById = Arrays.copyOf(typesById, typesById.length * 2);
            }
            assert typesById[newValue.getId()] == null;
            typesById[newValue.getId()] = newValue;
            if (newValue.isJavaLangObject()) {
                assert objectClass == null;
                objectClass = newValue;
            }
        }
        /*
             * Now that our type is correctly registered in the id-to-type array, make it accessible
             * by other threads.
             */
        Object oldValue = types.put(type, newValue);
        assert oldValue == claim;
        claim = null;
        ResolvedJavaType enclosingType = newValue.getWrapped().getEnclosingType();
        /* If not being currently constructed by this thread. */
        if (enclosingType != null && !types.containsKey(enclosingType)) {
            /* Make sure that the enclosing type is also in the universe. */
            newValue.getEnclosingType();
        }
        return newValue;
    } finally {
        /* In case of any exception, remove the claim so that we do not deadlock. */
        if (claim != null) {
            types.remove(type, claim);
        }
    }
}
Also used : UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind) SuppressFBWarnings(org.graalvm.compiler.core.common.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (org.graalvm.compiler.core.common.SuppressFBWarnings)3 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 SubstrateInstalledCode (com.oracle.svm.core.deopt.SubstrateInstalledCode)1 SubstrateCompiledCode (com.oracle.svm.core.graal.code.SubstrateCompiledCode)1 Condition (java.util.concurrent.locks.Condition)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1