From 1cfe6f330a60aa02c8f921b5f1772c85d65a4341 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Fri, 2 Feb 2018 23:44:07 +0100 Subject: [PATCH] Add missing Truffle boundaries --- .../ffi/impl/nodes/AttributesAccessNodes.java | 9 ++++-- .../r/ffi/impl/nodes/DuplicateNodes.java | 4 ++- .../truffle/r/nodes/builtin/base/IsNA.java | 4 +-- .../builtin/base/NamespaceFunctions.java | 5 +++- .../truffle/r/nodes/builtin/base/Prod.java | 6 ++-- .../r/nodes/builtin/fastr/FastRTrace.java | 7 +++-- .../nodes/builtin/helpers/DebugHandling.java | 3 +- .../nodes/builtin/helpers/TraceHandling.java | 28 +++++++++++++------ .../r/nodes/access/AccessSlotNode.java | 7 +++-- .../access/vector/ExtractVectorNode.java | 4 +-- .../access/vector/ReplaceVectorNode.java | 4 +-- .../r/nodes/binary/BinaryBooleanNode.java | 3 +- .../truffle/r/nodes/builtin/CastBuilder.java | 10 ++++++- .../r/nodes/builtin/EnvironmentNodes.java | 22 ++++++++------- .../unary/UnaryArithmeticReduceNode.java | 2 +- .../com/oracle/truffle/r/runtime/Utils.java | 7 ++++- .../truffle/r/runtime/data/RPairList.java | 3 +- .../truffle/r/runtime/data/RSymbol.java | 3 +- .../data/nodes/FastPathVectorAccess.java | 8 ++++-- .../data/nodes/SlowPathVectorAccess.java | 7 +++-- .../truffle/r/runtime/nmath/distr/Chisq.java | 14 ++++------ .../r/runtime/nmath/distr/RNchisq.java | 8 ++++-- .../truffle/r/runtime/nmath/distr/Rf.java | 9 ++++-- .../truffle/r/runtime/nmath/distr/Rt.java | 6 ++-- mx.fastr/native-image.properties | 5 +++- 25 files changed, 122 insertions(+), 66 deletions(-) diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java index 074f05de92..fe2516186b 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java @@ -126,7 +126,7 @@ public final class AttributesAccessNodes { public Object doArgs(RArgsValuesAndNames obj) { ArgumentsSignature signature = obj.getSignature(); if (signature.getLength() > 0 && signature.getName(0) != null) { - return RDataFactory.createSymbol(signature.getName(0)); + return getSymbol(signature.getName(0)); } return RNull.instance; } @@ -141,7 +141,7 @@ public final class AttributesAccessNodes { @Cached("create()") GetNamesAttributeNode getNamesAttributeNode) { RStringVector names = getNamesAttributeNode.getNames(obj); if (names != null && names.getLength() > 0) { - return RDataFactory.createSymbol(names.getDataAt(0)); + return getSymbol(names.getDataAt(0)); } return RNull.instance; } @@ -152,6 +152,11 @@ public final class AttributesAccessNodes { throw RInternalError.unimplemented("TAG is not implemented for type " + obj.getClass().getSimpleName()); } + @TruffleBoundary + private Object getSymbol(String name) { + return RDataFactory.createSymbol(name); + } + public static TAG create() { return TAGNodeGen.create(); } diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/DuplicateNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/DuplicateNodes.java index 10bb45981d..4eab0d8673 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/DuplicateNodes.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/DuplicateNodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,6 +22,7 @@ */ package com.oracle.truffle.r.ffi.impl.nodes; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.r.ffi.impl.nodes.DuplicateNodesFactory.DuplicateNodeGen; import com.oracle.truffle.r.runtime.data.RExternalPtr; @@ -36,6 +37,7 @@ public final class DuplicateNodes { public abstract static class DuplicateNode extends FFIUpCallNode.Arg2 { @Specialization + @TruffleBoundary public Object duplicateShareable(RShareable x, int deep) { assert !isReusableForDuplicate(x); return deep == 1 ? x.deepCopy() : x.copy(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java index 37d8da2fa8..1c4b0ccacd 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/IsNA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -171,7 +171,7 @@ public abstract class IsNA extends RBuiltinNode.Arg1 { @Fallback protected byte isNA(Object value) { - warning(RError.Message.IS_NA_TO_NON_VECTOR, Predef.typeName().apply(value)); + warning(RError.Message.IS_NA_TO_NON_VECTOR, Predef.getTypeName(value)); return RRuntime.LOGICAL_FALSE; } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NamespaceFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NamespaceFunctions.java index 6c3e1267f3..8abbd97ce0 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NamespaceFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/NamespaceFunctions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import static com.oracle.truffle.r.runtime.builtins.RBehavior.PURE; import static com.oracle.truffle.r.runtime.builtins.RBehavior.READS_STATE; import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.INTERNAL; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.r.nodes.builtin.NodeWithArgumentCasts.Casts; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; @@ -115,6 +116,7 @@ public class NamespaceFunctions { } @Specialization + @TruffleBoundary protected byte doIsNamespaceEnv(REnvironment env) { return RRuntime.asLogical(env.isNamespaceEnv()); } @@ -180,6 +182,7 @@ public class NamespaceFunctions { return RNull.instance; } + @TruffleBoundary private void doUnregisterNamespace(String name) { Object ns = REnvironment.unregisterNamespace(name); if (ns == null) { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Prod.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Prod.java index 2ca65bc642..88613eccd7 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Prod.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Prod.java @@ -4,7 +4,7 @@ * http://www.gnu.org/licenses/gpl-2.0.html * * Copyright (c) 2014, Purdue University - * Copyright (c) 2014, 2017, Oracle and/or its affiliates + * Copyright (c) 2014, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -154,7 +154,7 @@ public abstract class Prod extends RBuiltinNode.Arg2 { if (i == length) { return complexValue; } - throw error(RError.Message.INVALID_TYPE_ARGUMENT, Predef.typeName().apply(args.getArgument(i))); + throw error(RError.Message.INVALID_TYPE_ARGUMENT, Predef.getTypeName(args.getArgument(i))); } protected static double prodDouble(Object v, VectorAccess access, boolean naRm) { @@ -193,6 +193,6 @@ public abstract class Prod extends RBuiltinNode.Arg2 { @Fallback protected Object prod(Object v, @SuppressWarnings("unused") Object naRm) { - throw error(RError.Message.INVALID_TYPE_ARGUMENT, Predef.typeName().apply(v)); + throw error(RError.Message.INVALID_TYPE_ARGUMENT, Predef.getTypeName(v)); } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRTrace.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRTrace.java index 86630d20ab..c12826198a 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRTrace.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/fastr/FastRTrace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -50,6 +50,7 @@ import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.Closure; import com.oracle.truffle.r.runtime.data.RDataFactory; @@ -164,7 +165,7 @@ public class FastRTrace { } complexCase(func, tracer, exit, at, print, signature); visibility.execute(frame, true); - return func.toString(); + return Utils.toString(func); } @SuppressWarnings("unused") @@ -217,7 +218,7 @@ public class FastRTrace { throw RError.nyi(this, "method tracing"); } - return func.toString(); + return Utils.toString(func); } } } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/DebugHandling.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/DebugHandling.java index a00ce86a35..499760e739 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/DebugHandling.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/DebugHandling.java @@ -52,6 +52,7 @@ import com.oracle.truffle.r.runtime.RArguments; import com.oracle.truffle.r.runtime.RDeparse; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RSource; +import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.conn.StdConnections; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.context.RContext.ConsoleIO; @@ -750,7 +751,7 @@ public class DebugHandling { } private boolean isEnabled(EventContext ctx) { - return !disabled() && loopSourceSection != null && loopSourceSection.equals(ctx.getInstrumentedNode().getSourceSection()); + return !disabled() && loopSourceSection != null && Utils.equals(loopSourceSection, ctx.getInstrumentedNode().getSourceSection()); } private void returnCleanup() { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java index c7e0be6ae9..633f882eff 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/helpers/TraceHandling.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ import java.io.IOException; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.frame.MaterializedFrame; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.instrumentation.EventBinding; import com.oracle.truffle.api.instrumentation.EventContext; @@ -208,15 +209,26 @@ public class TraceHandling { @Override public void onEnter(EventContext context, VirtualFrame frame) { if (!disabled()) { + MaterializedFrame materializedFrame = frame.materialize(); if (print) { - try { - String callString = getCallSource(frame); - outputHandler.writeString("Tracing " + callString + " on entry", true); - } catch (IOException ex) { - throw RError.ioError(RError.SHOW_CALLER2, ex); - } + printEnter(materializedFrame); } - RContext.getEngine().eval(tracer, frame.materialize()); + evalTracer(materializedFrame); + } + } + + @TruffleBoundary + private void evalTracer(MaterializedFrame frame) { + RContext.getEngine().eval(tracer, frame); + } + + @TruffleBoundary + private void printEnter(MaterializedFrame frame) { + try { + String callString = getCallSource(frame); + outputHandler.writeString("Tracing " + callString + " on entry", true); + } catch (IOException ex) { + throw RError.ioError(RError.SHOW_CALLER2, ex); } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/AccessSlotNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/AccessSlotNode.java index c8d8a6c3f1..bc99584c85 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/AccessSlotNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/AccessSlotNode.java @@ -6,12 +6,13 @@ * Copyright (c) 1995, 1996, 1997 Robert Gentleman and Ross Ihaka * Copyright (c) 1995-2014, The R Core Team * Copyright (c) 2002-2008, The R Foundation - * Copyright (c) 2015, 2017, Oracle and/or its affiliates + * Copyright (c) 2015, 2018, Oracle and/or its affiliates * * All rights reserved. */ package com.oracle.truffle.r.nodes.access; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; @@ -67,9 +68,8 @@ public abstract class AccessSlotNode extends BaseAccessSlotNode { return RContext.getEngine().evalFunction(dataPart, methodsNamespace.getFrame(), RCaller.create(null, RASTUtils.getOriginalCall(this)), true, null, object); } - // this is really a fallback specialization but @Fallback does not work here (because of the - // type of "object"?) @Specialization(guards = {"!slotAccessAllowed(object)", "!isDotData(name)"}) + @TruffleBoundary protected Object getSlot(RAttributable object, String name, @Cached("create()") GetClassAttributeNode getClassNode) { RStringVector classAttr = getClassNode.getClassAttr(object); @@ -84,6 +84,7 @@ public abstract class AccessSlotNode extends BaseAccessSlotNode { } @Fallback + @TruffleBoundary protected Object getSlot(Object object, String name) { throw error(RError.Message.SLOT_CANNOT_GET, name, RRuntime.getRTypeName(object)); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java index 16eff7b81b..c8504c82d6 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ExtractVectorNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -363,6 +363,6 @@ public abstract class ExtractVectorNode extends RBaseNode { @Fallback protected Object access(Object object, Object[] positions, Object exact, Object dropDimensions) { CompilerDirectives.transferToInterpreter(); - throw error(RError.Message.OBJECT_NOT_SUBSETTABLE, Predef.typeName().apply(object)); + throw error(RError.Message.OBJECT_NOT_SUBSETTABLE, Predef.getTypeName(object)); } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java index 093cee2ae2..d667e9f75d 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/ReplaceVectorNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -351,6 +351,6 @@ public abstract class ReplaceVectorNode extends RBaseNode { @Fallback protected Object access(Object object, Object[] positions, Object value) { CompilerDirectives.transferToInterpreter(); - throw error(RError.Message.OBJECT_NOT_SUBSETTABLE, Predef.typeName().apply(object)); + throw error(RError.Message.OBJECT_NOT_SUBSETTABLE, Predef.getTypeName(object)); } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java index 61e9e4df60..0a63fd0fac 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/BinaryBooleanNode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -234,6 +234,7 @@ public abstract class BinaryBooleanNode extends RBuiltinNode.Arg2 { } @Specialization(guards = {"(isRMissing(left) || isRMissing(right))"}) + @TruffleBoundary protected Object doOneArg(@SuppressWarnings("unused") Object left, @SuppressWarnings("unused") Object right) { throw error(RError.Message.IS_OF_WRONG_ARITY, 1, factory.createOperation().opName(), 2); } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java index fd5623610a..55fe8e2651 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/CastBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,9 @@ package com.oracle.truffle.r.nodes.builtin; import java.util.Arrays; import java.util.function.Function; +import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.interop.TruffleObject; import com.oracle.truffle.r.nodes.builtin.casts.Filter; import com.oracle.truffle.r.nodes.builtin.casts.Filter.AndFilter; @@ -789,7 +791,13 @@ public final class CastBuilder { * @return a function returning the type name of its argument */ public static Function<Object, String> typeName() { + CompilerAsserts.neverPartOfCompilation(); return arg -> RRuntime.getRTypeName(arg); } + + @TruffleBoundary + public static String getTypeName(Object arg) { + return RRuntime.getRTypeName(arg); + } } } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/EnvironmentNodes.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/EnvironmentNodes.java index 9a24476c92..5d6db966d1 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/EnvironmentNodes.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/EnvironmentNodes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,6 +23,7 @@ package com.oracle.truffle.r.nodes.builtin; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.frame.FrameDescriptor; @@ -61,15 +62,16 @@ public final class EnvironmentNodes { public abstract REnvironment execute(Object listOrNull, REnvironment target, String envName, REnvironment parentEnv); @Specialization(guards = "isEmpty(list)") - protected REnvironment doEmptyList(@SuppressWarnings("unused") RAbstractListVector list, REnvironment target, String envName, REnvironment parentEnv) { - REnvironment createNewEnv; - if (target == null) { - createNewEnv = RDataFactory.createNewEnv(envName); - RArguments.initializeEnclosingFrame(createNewEnv.getFrame(), parentEnv.getFrame()); - createNewEnv.setParent(parentEnv); - } else { - createNewEnv = target; - } + protected REnvironment doEmptyList(@SuppressWarnings("unused") RAbstractListVector list, REnvironment target, String envName, REnvironment parentEnv, + @Cached("createBinaryProfile()") ConditionProfile nullTargetProfile) { + return nullTargetProfile.profile(target == null) ? createNewEnv(envName, parentEnv) : target; + } + + @TruffleBoundary + private REnvironment createNewEnv(String envName, REnvironment parentEnv) { + REnvironment createNewEnv = RDataFactory.createNewEnv(envName); + RArguments.initializeEnclosingFrame(createNewEnv.getFrame(), parentEnv.getFrame()); + createNewEnv.setParent(parentEnv); return createNewEnv; } diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticReduceNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticReduceNode.java index 4f24d6d830..eed047314b 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticReduceNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/unary/UnaryArithmeticReduceNode.java @@ -419,7 +419,7 @@ public abstract class UnaryArithmeticReduceNode extends RBaseNode { @Fallback protected Object doFallback(Object obj, @SuppressWarnings("unused") boolean naRm, @SuppressWarnings("unused") boolean infinite) { - throw error(RError.Message.INVALID_TYPE_ARGUMENT, Predef.typeName().apply(obj)); + throw error(RError.Message.INVALID_TYPE_ARGUMENT, Predef.getTypeName(obj)); } protected UnaryArithmeticReduceNode createRecursive() { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java index 976c45f6f8..18e5348b3e 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Utils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -700,6 +700,11 @@ public final class Utils { return obj.toString(); } + @TruffleBoundary + public static boolean equals(Object a, Object b) { + return a.equals(b); + } + @TruffleBoundary public static String stringFormat(String format, Object... objects) { return String.format(format, objects); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java index feced1226c..089225a7db 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -271,6 +271,7 @@ public final class RPairList extends RSharingAttributeStorage implements RAbstra } @Override + @TruffleBoundary public RPairList copy() { BaseVectorFactory dataFactory = RDataFactory.getInstance(); RPairList curr = dataFactory.createPairList(); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RSymbol.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RSymbol.java index 903fd638fd..5785517755 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RSymbol.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RSymbol.java @@ -28,6 +28,7 @@ import java.util.function.Function; import com.oracle.truffle.api.CompilerAsserts; import com.oracle.truffle.api.CompilerDirectives; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.CompilerDirectives.ValueType; import com.oracle.truffle.r.runtime.RType; @@ -51,8 +52,8 @@ public final class RSymbol extends RAttributeStorage { this.name = name; } + @TruffleBoundary public static RSymbol install(String name) { - CompilerAsserts.neverPartOfCompilation(); return symbolTable.computeIfAbsent(name, RSymbol::new); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/FastPathVectorAccess.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/FastPathVectorAccess.java index 4d8948d3f6..aacb25a85f 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/FastPathVectorAccess.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/FastPathVectorAccess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,7 +22,8 @@ */ package com.oracle.truffle.r.runtime.data.nodes; -import com.oracle.truffle.api.CompilerAsserts; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RInternalError; @@ -43,6 +44,7 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; public abstract class FastPathVectorAccess extends VectorAccess { protected boolean naReported; // TODO: move this into the iterator + private final BranchProfile warningReportedProfile = BranchProfile.create(); protected FastPathVectorAccess(Object value) { super(value.getClass(), value instanceof RAbstractContainer ? ((RAbstractContainer) value).getInternalStore() != null : true); @@ -54,8 +56,8 @@ public abstract class FastPathVectorAccess extends VectorAccess { } protected final void warning(RError.Message message) { - CompilerAsserts.neverPartOfCompilation(); if (!naReported) { + warningReportedProfile.enter(); RError.warning(RError.SHOW_CALLER, message); naReported = true; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SlowPathVectorAccess.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SlowPathVectorAccess.java index 5aeab7e217..47b915f331 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SlowPathVectorAccess.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/nodes/SlowPathVectorAccess.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,6 +23,8 @@ package com.oracle.truffle.r.runtime.data.nodes; import com.oracle.truffle.api.CompilerAsserts; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; +import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RInternalError; @@ -41,6 +43,7 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractContainer; public abstract class SlowPathVectorAccess extends VectorAccess { protected boolean naReported; // TODO: move this into the iterator + private final BranchProfile warningReportedProfile = BranchProfile.create(); protected SlowPathVectorAccess() { // VectorAccess.supports has an assertion that relies on this being Object.class @@ -53,8 +56,8 @@ public abstract class SlowPathVectorAccess extends VectorAccess { } protected final void warning(RError.Message message) { - CompilerAsserts.neverPartOfCompilation(); if (!naReported) { + warningReportedProfile.enter(); RError.warning(RError.SHOW_CALLER, message); naReported = true; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Chisq.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Chisq.java index 3d79d3d43f..79c51e4865 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Chisq.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Chisq.java @@ -5,7 +5,7 @@ * * Copyright (C) 1998 Ross Ihaka * Copyright (c) 2000, The R Core Team - * Copyright (c) 2016, 2017, Oracle and/or its affiliates + * Copyright (c) 2016, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -48,16 +48,14 @@ public final class Chisq { } public static final class RChisq extends RandFunction1_Double { - public static double rchisq(double df, RandomNumberProvider rand) { + @Child private RGamma rGamma = new RGamma(); + + @Override + public double execute(double df, RandomNumberProvider rand) { if (!Double.isFinite(df) || df < 0.0) { return RMathError.defaultError(); } - return new RGamma().execute(df / 2.0, 2.0, rand); - } - - @Override - public double execute(double a, RandomNumberProvider rand) { - return rchisq(a, rand); + return rGamma.execute(df / 2.0, 2.0, rand); } } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/RNchisq.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/RNchisq.java index ca4115c927..2ac0cbee0c 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/RNchisq.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/RNchisq.java @@ -5,7 +5,7 @@ * * Copyright (c) 1995-2015, The R Core Team * Copyright (c) 2015, The R Foundation - * Copyright (c) 2016, 2017, Oracle and/or its affiliates + * Copyright (c) 2016, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -16,9 +16,11 @@ package com.oracle.truffle.r.runtime.nmath.distr; import com.oracle.truffle.r.runtime.nmath.RMathError; import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandFunction2_Double; import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandomNumberProvider; +import com.oracle.truffle.r.runtime.nmath.distr.Chisq.RChisq; public final class RNchisq extends RandFunction2_Double { - private final RGamma rgamma = new RGamma(); + @Child private RGamma rgamma = new RGamma(); + @Child private RChisq rchisq = new RChisq(); @Override public double execute(double df, double lambda, RandomNumberProvider rand) { @@ -31,7 +33,7 @@ public final class RNchisq extends RandFunction2_Double { } else { double r = RPois.rpois(lambda / 2., rand); if (r > 0.) { - r = Chisq.RChisq.rchisq(2. * r, rand); + r = rchisq.execute(2. * r, rand); } if (df > 0.) { r += rgamma.execute(df / 2., 2., rand); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rf.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rf.java index 56dfc48308..52837bccfc 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rf.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rf.java @@ -5,7 +5,7 @@ * * Copyright (C) 1998 Ross Ihaka * Copyright (c) 1998--2008, The R Core Team - * Copyright (c) 2016, 2017, Oracle and/or its affiliates + * Copyright (c) 2016, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -14,8 +14,11 @@ package com.oracle.truffle.r.runtime.nmath.distr; import com.oracle.truffle.r.runtime.nmath.RMathError; import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandFunction2_Double; import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandomNumberProvider; +import com.oracle.truffle.r.runtime.nmath.distr.Chisq.RChisq; public final class Rf extends RandFunction2_Double { + @Child private RChisq rchisq = new RChisq(); + @Override public double execute(double n1, double n2, RandomNumberProvider rand) { if (Double.isNaN(n1) || Double.isNaN(n2) || n1 <= 0. || n2 <= 0.) { @@ -24,8 +27,8 @@ public final class Rf extends RandFunction2_Double { double v1; double v2; - v1 = Double.isFinite(n1) ? (Chisq.RChisq.rchisq(n1, rand) / n1) : 1; - v2 = Double.isFinite(n2) ? (Chisq.RChisq.rchisq(n2, rand) / n2) : 1; + v1 = Double.isFinite(n1) ? (rchisq.execute(n1, rand) / n1) : 1; + v2 = Double.isFinite(n2) ? (rchisq.execute(n2, rand) / n2) : 1; return v1 / v2; } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rt.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rt.java index dffa27a4e7..74cb57b646 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rt.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/nmath/distr/Rt.java @@ -5,7 +5,7 @@ * * Copyright (C) 1998 Ross Ihaka * Copyright (c) 1998--2008, The R Core Team - * Copyright (c) 2016, 2017, Oracle and/or its affiliates + * Copyright (c) 2016, 2018, Oracle and/or its affiliates * * All rights reserved. */ @@ -17,6 +17,8 @@ import com.oracle.truffle.r.runtime.nmath.RandomFunctions.RandomNumberProvider; import com.oracle.truffle.r.runtime.nmath.distr.Chisq.RChisq; public final class Rt extends RandFunction1_Double { + @Child private RChisq rchisq = new RChisq(); + @Override public double execute(double df, RandomNumberProvider rand) { if (Double.isNaN(df) || df <= 0.0) { @@ -26,7 +28,7 @@ public final class Rt extends RandFunction1_Double { if (!Double.isFinite(df)) { return rand.normRand(); } else { - return rand.normRand() / Math.sqrt(RChisq.rchisq(df, rand) / df); + return rand.normRand() / Math.sqrt(rchisq.execute(df, rand) / df); } } } diff --git a/mx.fastr/native-image.properties b/mx.fastr/native-image.properties index bc39dee019..a70e3e7020 100644 --- a/mx.fastr/native-image.properties +++ b/mx.fastr/native-image.properties @@ -10,4 +10,7 @@ JavaArgs = \ -Dfastr.internal.grid.awt.support=false \ -Xmx6G -Args = -H:Class=com.oracle.truffle.r.launcher.RCommand +Args = -H:Class=com.oracle.truffle.r.launcher.RCommand \ + -H:MaxRuntimeCompileMethods=8000 \ + -H:TruffleCheckFrameImplementation=false \ + -H:TruffleCheckNeverPartOfCompilation=true -- GitLab