Search in sources :

Example 6 with ImmutableTriple

use of org.apache.commons.lang3.tuple.ImmutableTriple in project robovm by robovm.

the class TrampolineCompiler method compile.

public void compile(ModuleBuilder mb, Clazz currentClass, Trampoline t, Set<String> dependencies, Set<Triple<String, String, String>> methodDependencies) {
    this.mb = mb;
    addDependencyIfNeeded(dependencies, currentClass, t);
    /*
         * Check if the target class exists and is accessible. Also check that
         * field accesses and method calls are compatible with the target 
         * field/method and that the field/method is accessible to the caller.
         * If any of the tests fail the weak trampoline function created by the
         * ClassCompiler will be overridden with a function which throws an
         * appropriate exception.
         */
    Function errorFn = new FunctionBuilder(t).linkage(external).build();
    if (!checkClassExists(errorFn, t) || !checkClassAccessible(errorFn, t)) {
        mb.addFunction(errorFn);
        return;
    }
    if (t instanceof New) {
        SootClass target = config.getClazzes().load(t.getTarget()).getSootClass();
        if (target.isAbstract() || target.isInterface()) {
            call(errorFn, BC_THROW_INSTANTIATION_ERROR, errorFn.getParameterRef(0), mb.getString(t.getTarget().replace('/', '.')));
            errorFn.add(new Unreachable());
            mb.addFunction(errorFn);
            return;
        }
        String fnName = Symbols.clinitWrapperSymbol(Symbols.allocatorSymbol(t.getTarget()));
        alias(t, fnName);
    } else if (t instanceof Instanceof) {
        if (isArray(t.getTarget())) {
            FunctionRef fnRef = createInstanceofArray((Instanceof) t);
            alias(t, fnRef.getName());
        } else {
            String fnName = Symbols.instanceofSymbol(t.getTarget());
            alias(t, fnName);
        }
    } else if (t instanceof Checkcast) {
        if (isArray(t.getTarget())) {
            FunctionRef fnRef = createCheckcastArray((Checkcast) t);
            alias(t, fnRef.getName());
        } else {
            String fnName = Symbols.checkcastSymbol(t.getTarget());
            alias(t, fnName);
        }
    } else if (t instanceof LdcClass) {
        if (isArray(t.getTarget())) {
            FunctionRef fnRef = createLdcArray((LdcClass) t);
            alias(t, fnRef.getName());
        } else {
            String fnName = Symbols.ldcExternalSymbol(t.getTarget());
            alias(t, fnName);
        }
    } else if (t instanceof Anewarray) {
        FunctionRef fnRef = createAnewarray((Anewarray) t);
        alias(t, fnRef.getName());
    } else if (t instanceof Multianewarray) {
        FunctionRef fnRef = createMultianewarray((Multianewarray) t);
        alias(t, fnRef.getName());
    } else if (t instanceof FieldAccessor) {
        SootField field = resolveField(errorFn, (FieldAccessor) t);
        if (field != null) {
            dependencies.add(getInternalName(field.getDeclaringClass()));
        }
        if (field == null || !checkMemberAccessible(errorFn, t, field)) {
            mb.addFunction(errorFn);
            return;
        }
        Clazz caller = config.getClazzes().load(t.getCallingClass());
        Clazz target = config.getClazzes().load(t.getTarget());
        if (!((FieldAccessor) t).isGetter() && field.isFinal() && caller != target) {
            // Only the class declaring a final field may write to it.
            // (Actually only <init>/<clinit> methods may write to it but we 
            // don't know which method is accessing the field at this point)
            throwIllegalAccessError(errorFn, ATTEMPT_TO_WRITE_TO_FINAL_FIELD, target, field.getName(), caller);
            mb.addFunction(errorFn);
            return;
        }
        if (!field.isStatic()) {
            createInlinedAccessorForInstanceField((FieldAccessor) t, field);
        } else {
            createTrampolineAliasForField((FieldAccessor) t, field);
        }
    } else if (t instanceof Invokeinterface) {
        SootMethod rm = resolveInterfaceMethod(errorFn, (Invokeinterface) t);
        if (rm != null) {
            methodDependencies.add(new ImmutableTriple<String, String, String>(getInternalName(rm.getDeclaringClass()), rm.getName(), getDescriptor(rm)));
        }
        if (rm == null || !checkMemberAccessible(errorFn, t, rm)) {
            mb.addFunction(errorFn);
            return;
        }
        createTrampolineAliasForMethod((Invoke) t, rm);
    } else if (t instanceof Invoke) {
        SootMethod method = resolveMethod(errorFn, (Invoke) t);
        if (method != null) {
            methodDependencies.add(new ImmutableTriple<String, String, String>(getInternalName(method.getDeclaringClass()), method.getName(), getDescriptor(method)));
        }
        if (method == null || !checkMemberAccessible(errorFn, t, method)) {
            mb.addFunction(errorFn);
            return;
        }
        if (t instanceof Invokespecial && method.isAbstract()) {
            call(errorFn, BC_THROW_ABSTRACT_METHOD_ERROR, errorFn.getParameterRef(0), mb.getString(String.format(NO_SUCH_METHOD_ERROR, method.getDeclaringClass(), method.getName(), getDescriptor(method))));
            errorFn.add(new Unreachable());
            mb.addFunction(errorFn);
            return;
        }
        createTrampolineAliasForMethod((Invoke) t, method);
    }
}
Also used : New(org.robovm.compiler.trampoline.New) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) Anewarray(org.robovm.compiler.trampoline.Anewarray) Multianewarray(org.robovm.compiler.trampoline.Multianewarray) SootClass(soot.SootClass) FieldAccessor(org.robovm.compiler.trampoline.FieldAccessor) Invokeinterface(org.robovm.compiler.trampoline.Invokeinterface) Invoke(org.robovm.compiler.trampoline.Invoke) Invokespecial(org.robovm.compiler.trampoline.Invokespecial) Function(org.robovm.compiler.llvm.Function) Unreachable(org.robovm.compiler.llvm.Unreachable) LdcClass(org.robovm.compiler.trampoline.LdcClass) Instanceof(org.robovm.compiler.trampoline.Instanceof) SootMethod(soot.SootMethod) SootField(soot.SootField) Clazz(org.robovm.compiler.clazz.Clazz) Checkcast(org.robovm.compiler.trampoline.Checkcast) FunctionRef(org.robovm.compiler.llvm.FunctionRef)

Example 7 with ImmutableTriple

use of org.apache.commons.lang3.tuple.ImmutableTriple in project alluxio by Alluxio.

the class PermissionCheckTest method getPermissionOther.

@Test
public void getPermissionOther() throws Exception {
    ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
    permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
    LockedInodePath lockedInodePath = getLockedInodePath(permissions);
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_2.getUser())) {
        PermissionChecker checker = new PermissionChecker(mInodeTree);
        Mode.Bits actual = checker.getPermission(lockedInodePath);
        Assert.assertEquals(Mode.Bits.READ, actual);
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) MutableLockedInodePath(alluxio.master.file.meta.MutableLockedInodePath) LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) Mode(alluxio.security.authorization.Mode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with ImmutableTriple

use of org.apache.commons.lang3.tuple.ImmutableTriple in project alluxio by Alluxio.

the class PermissionCheckTest method getPermissionGroup.

@Test
public void getPermissionGroup() throws Exception {
    ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
    permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
    LockedInodePath lockedInodePath = getLockedInodePath(permissions);
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_3.getUser())) {
        PermissionChecker checker = new PermissionChecker(mInodeTree);
        Mode.Bits actual = checker.getPermission(lockedInodePath);
        Assert.assertEquals(Mode.Bits.READ_EXECUTE, actual);
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) MutableLockedInodePath(alluxio.master.file.meta.MutableLockedInodePath) LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) Mode(alluxio.security.authorization.Mode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with ImmutableTriple

use of org.apache.commons.lang3.tuple.ImmutableTriple in project gatk by broadinstitute.

the class CoverageModelEMComputeBlock method getBiasLatentPosteriorDataRegularized.

/**
     * Calculates the contribution of the target-space block represented by this compute node
     * to the E-step for $z_{s\mu}$ w/ regularization. The result is a triple
     * of INDArrays (contribGMatrix, contribZ, contribFilter). The first two were defined
     * in {@link CoverageModelEMComputeBlock#getBiasLatentPosteriorDataUnregularized()}. The third
     * INDArray is:
     *
     *      contribFilter = [W]^T [F.W]
     *
     * @return an {@link ImmutableTriple} of contribGMatrix (left), contribZ (middle), contribFilter (right)
     */
@QueriesICG
public ImmutableTriple<INDArray, INDArray, INDArray> getBiasLatentPosteriorDataRegularized() {
    assertBiasCovariatesEnabled();
    final ImmutablePair<INDArray, INDArray> unreg = getBiasLatentPosteriorDataUnregularized();
    final INDArray contribFilter = getINDArrayFromCache(CoverageModelICGCacheNode.W_tl).transpose().mmul(getINDArrayFromCache(CoverageModelICGCacheNode.F_W_tl));
    return new ImmutableTriple<>(unreg.left, unreg.right, contribFilter);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple)

Example 10 with ImmutableTriple

use of org.apache.commons.lang3.tuple.ImmutableTriple in project gatk-protected by broadinstitute.

the class CoverageModelEMComputeBlock method getBiasLatentPosteriorDataRegularized.

/**
     * Calculates the contribution of the target-space block represented by this compute node
     * to the E-step for $z_{s\mu}$ w/ regularization. The result is a triple
     * of INDArrays (contribGMatrix, contribZ, contribFilter). The first two were defined
     * in {@link CoverageModelEMComputeBlock#getBiasLatentPosteriorDataUnregularized()}. The third
     * INDArray is:
     *
     *      contribFilter = [W]^T [F.W]
     *
     * @return an {@link ImmutableTriple} of contribGMatrix (left), contribZ (middle), contribFilter (right)
     */
@QueriesICG
public ImmutableTriple<INDArray, INDArray, INDArray> getBiasLatentPosteriorDataRegularized() {
    assertBiasCovariatesEnabled();
    final ImmutablePair<INDArray, INDArray> unreg = getBiasLatentPosteriorDataUnregularized();
    final INDArray contribFilter = getINDArrayFromCache(CoverageModelICGCacheNode.W_tl).transpose().mmul(getINDArrayFromCache(CoverageModelICGCacheNode.F_W_tl));
    return new ImmutableTriple<>(unreg.left, unreg.right, contribFilter);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple)

Aggregations

ImmutableTriple (org.apache.commons.lang3.tuple.ImmutableTriple)17 Triple (org.apache.commons.lang3.tuple.Triple)12 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 LockedInodePath (alluxio.master.file.meta.LockedInodePath)4 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)3 MutableLockedInodePath (alluxio.master.file.meta.MutableLockedInodePath)3 Mode (alluxio.security.authorization.Mode)3 List (java.util.List)3 ConfigProperty (alluxio.grpc.ConfigProperty)2 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)2 Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)2 StoredBlock (co.rsk.bitcoinj.core.StoredBlock)2 TIntList (gnu.trove.list.TIntList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 InputStream (java.io.InputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 BigInteger (java.math.BigInteger)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2