oracle / fastr

A high-performance implementation of the R programming language, built on GraalVM.
Other
626 stars 64 forks source link

RC11 java.lang.ArrayIndexOutOfBoundsException escapes tryCatch #53

Closed NRBPerdijk closed 5 years ago

NRBPerdijk commented 5 years ago

Hello!

(Unsure if this is related to #50 )

When I run the code snippet below using GraalVM, it prints the numbers 1 through 11 and then dies with a stacktrace (see further below), stating java.lang.ArrayIndexOutOfBoundsException. The snippet works fine in regular R (catching & printing the error and "Yah, finished"). Depending on throwing errors for application logic is certainly not pretty, but it is a work around we were trying for other issues in RC11 and it is behaviour that is different from regular R, so we were surprised!

library("pdftools")

    object <- "https://www.graalvm.org/uploads/graalvm-language-level-virtualization-oracle-tech-papers.pdf"
    page <- 1

    while(TRUE){

        img_pdf <- tryCatch({
            print(page)
            pdf_render_page(object, page)
        },
        error = function(cond){
            print(cond)
            print("Yah, finished!")
            return(FALSE)
        })

        if (is.logical(img_pdf)) {
            return()
        } else {
            page <- page + 1
        }
    }
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
Exception in thread "main" org.graalvm.polyglot.PolyglotException: com.oracle.truffle.r.runtime.RInternalError: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:325)
    at <R> poppler_render_page(Unknown)
    at <R> pdf_render_page(unknown.r:1:0-87)
    at <R> <promise>1572487132(src/main/r/complicatedTextProcessing.R:20:438-466)
    at <R> doTryCatch(Unknown)
    at <R> tryCatchOne(unknown.r:1:0-49)
    at <R> tryCatchList(unknown.r:1:0-50)
    at <R> tryCatch(unknown.r:1:0-47)
    at <R> processText(src/main/r/complicatedTextProcessing.R:18-26:391-606)
    at com.oracle.truffle.polyglot.FunctionProxyHandler.invoke(HostInteropReflect.java:436)
    at com.sun.proxy.$Proxy31.apply(Unknown Source)
    at Main$.delayedEndpoint$Main$1(Main.scala:61)
    at Main$delayedInit$body.apply(Main.scala:7)
    at scala.Function0.apply$mcV$sp(Function0.scala:34)
    at scala.Function0.apply$mcV$sp$(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App.$anonfun$main$1$adapted(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at scala.App.main(App.scala:76)
    at scala.App.main$(App.scala:74)
    at Main$.main(Main.scala:7)
    at Main.main(Main.scala)
Original Internal Error: 
com.oracle.truffle.r.runtime.RInternalError: java.lang.ArrayIndexOutOfBoundsException: -1
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:325)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callInlined(OptimizedCallTarget.java:229)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.nodes.access.WriteLocalFrameVariableNodeGen.execute_generic3(WriteLocalFrameVariableNodeGen.java:114)
    at com.oracle.truffle.r.nodes.access.WriteLocalFrameVariableNodeGen.execute(WriteLocalFrameVariableNodeGen.java:48)
    at com.oracle.truffle.r.nodes.access.WriteVariableSyntaxNode.voidExecute(WriteVariableSyntaxNode.java:60)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:86)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.runtime.nodes.RNode.visibleExecute(RNode.java:74)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:88)
    at com.oracle.truffle.r.nodes.function.WrapArgumentBaseNode.visibleExecute(WrapArgumentBaseNode.java:63)
    at com.oracle.truffle.r.nodes.InlineCacheNode.doCached(InlineCacheNode.java:70)
    at com.oracle.truffle.r.nodes.InlineCacheNodeGen.execute(InlineCacheNodeGen.java:36)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.generateValueDefault(PromiseHelperNode.java:170)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.evaluate(PromiseHelperNode.java:152)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.generateValueNonDefault(PromiseHelperNode.java:191)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.evaluate(PromiseHelperNode.java:154)
    at com.oracle.truffle.r.nodes.access.variables.ReadVariableNode.executeInternal(ReadVariableNode.java:295)
    at com.oracle.truffle.r.nodes.access.variables.LookupNode.visibleExecute(ReadVariableNode.java:113)
    at com.oracle.truffle.r.nodes.function.WrapArgumentBaseNode.visibleExecute(WrapArgumentBaseNode.java:63)
    at com.oracle.truffle.r.engine.REngine$AnonymousBodyNode.visibleExecute(REngine.java:632)
    at com.oracle.truffle.r.engine.REngine$AnonymousRootNode.execute(REngine.java:559)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:209)
    at com.oracle.truffle.r.runtime.data.Closure.eval(Closure.java:138)
    at com.oracle.truffle.r.nodes.InlineCacheNode.evalPromise(InlineCacheNode.java:94)
    at com.oracle.truffle.r.nodes.InlineCacheNode.doGeneric(InlineCacheNode.java:75)
    at com.oracle.truffle.r.nodes.InlineCacheNodeGen.execute(InlineCacheNodeGen.java:42)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.generateValueDefault(PromiseHelperNode.java:170)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.generateValueNonDefault(PromiseHelperNode.java:206)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.evaluate(PromiseHelperNode.java:154)
    at com.oracle.truffle.r.nodes.access.variables.LocalReadVariableNode.execute(LocalReadVariableNode.java:154)
    at com.oracle.truffle.r.nodes.access.variables.LocalReadVariableNode.execute(LocalReadVariableNode.java:84)
    at com.oracle.truffle.r.nodes.function.PeekLocalVariableNode.execute(PeekLocalVariableNode.java:50)
    at com.oracle.truffle.r.nodes.function.PeekLocalVariableNode.visibleExecute(PeekLocalVariableNode.java:60)
    at com.oracle.truffle.r.nodes.builtin.base.ReturnSpecial.execute(Return.java:58)
    at com.oracle.truffle.r.nodes.function.RCallSpecialNode.execute(RCallSpecialNode.java:306)
    at com.oracle.truffle.r.nodes.function.RCallSpecialNode.visibleExecute(RCallSpecialNode.java:378)
    at com.oracle.truffle.r.nodes.function.WrapArgumentBaseNode.visibleExecute(WrapArgumentBaseNode.java:63)
    at com.oracle.truffle.r.nodes.InlineCacheNode.doCached(InlineCacheNode.java:70)
    at com.oracle.truffle.r.nodes.InlineCacheNodeGen.execute(InlineCacheNodeGen.java:36)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.generateValueDefault(PromiseHelperNode.java:170)
    at com.oracle.truffle.r.nodes.function.PromiseHelperNode.evaluate(PromiseHelperNode.java:152)
    at com.oracle.truffle.r.nodes.access.variables.ReadVariableNode.executeInternal(ReadVariableNode.java:295)
    at com.oracle.truffle.r.nodes.access.variables.LookupNode.visibleExecute(ReadVariableNode.java:113)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:88)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.nodes.access.WriteLocalFrameVariableNodeGen.execute_generic3(WriteLocalFrameVariableNodeGen.java:114)
    at com.oracle.truffle.r.nodes.access.WriteLocalFrameVariableNodeGen.execute(WriteLocalFrameVariableNodeGen.java:48)
    at com.oracle.truffle.r.nodes.access.WriteVariableSyntaxNode.voidExecute(WriteVariableSyntaxNode.java:60)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:86)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.runtime.nodes.RNode.visibleExecute(RNode.java:74)
    at com.oracle.truffle.r.nodes.control.IfNode.visibleExecute(IfNode.java:93)
    at com.oracle.truffle.r.nodes.control.IfNode.visibleExecute(IfNode.java:96)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:88)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.runtime.nodes.RNode.visibleExecute(RNode.java:74)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:88)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.nodes.access.WriteLocalFrameVariableNodeGen.execute_generic3(WriteLocalFrameVariableNodeGen.java:114)
    at com.oracle.truffle.r.nodes.access.WriteLocalFrameVariableNodeGen.execute(WriteLocalFrameVariableNodeGen.java:48)
    at com.oracle.truffle.r.nodes.access.WriteVariableSyntaxNode.voidExecute(WriteVariableSyntaxNode.java:60)
    at com.oracle.truffle.r.nodes.control.BlockNode.voidExecute(BlockNode.java:70)
    at com.oracle.truffle.r.nodes.control.WhileNode$WhileRepeatingNode.executeRepeating(WhileNode.java:83)
    at org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode.profilingLoop(OptimizedOSRLoopNode.java:135)
    at org.graalvm.compiler.truffle.runtime.OptimizedOSRLoopNode.executeLoop(OptimizedOSRLoopNode.java:112)
    at com.oracle.truffle.r.nodes.control.WhileNode.execute(WhileNode.java:54)
    at com.oracle.truffle.r.runtime.nodes.RNode.voidExecute(RNode.java:66)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:86)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.r.nodes.function.call.CallRFunctionNode.execute(CallRFunctionNode.java:59)
    at com.oracle.truffle.r.nodes.function.RCallNode$DispatchedCallNode.execute(RCallNode.java:1180)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.executeAndSpecialize(RCallNodeGen.java:714)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:678)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.executeAndSpecialize(RCallNodeGen.java:226)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:151)
    at com.oracle.truffle.r.nodes.function.call.RExplicitCallNode.doCall(RExplicitCallNode.java:69)
    at com.oracle.truffle.r.nodes.function.call.RExplicitCallNodeGen.executeAndSpecialize(RExplicitCallNodeGen.java:44)
    at com.oracle.truffle.r.nodes.function.call.RExplicitCallNodeGen.execute(RExplicitCallNodeGen.java:31)
    at com.oracle.truffle.r.nodes.function.call.RExplicitCallNode.call(RExplicitCallNode.java:52)
    at com.oracle.truffle.r.engine.interop.RFunctionMR$RFunctionExecuteNode.access(RFunctionMR.java:71)
    at com.oracle.truffle.r.engine.interop.RFunctionMRForeign$RFunctionExecuteSubNode.accessWithTarget(RFunctionMRForeign.java:124)
    at com.oracle.truffle.r.engine.interop.RFunctionMRForeignFactory$RFunctionExecuteSubNodeGen.executeAndSpecialize(RFunctionMRForeignFactory.java:60)
    at com.oracle.truffle.r.engine.interop.RFunctionMRForeignFactory$RFunctionExecuteSubNodeGen.executeWithTarget(RFunctionMRForeignFactory.java:44)
    at com.oracle.truffle.r.engine.interop.RFunctionMRForeign$RFunctionExecuteSubNode$EXECUTERootNode.execute(RFunctionMRForeign.java:146)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.api.interop.InteropAccessNode.doCached(InteropAccessNode.java:206)
    at com.oracle.truffle.api.interop.InteropAccessNodeGen.executeAndSpecialize(InteropAccessNodeGen.java:82)
    at com.oracle.truffle.api.interop.InteropAccessNodeGen.executeImpl(InteropAccessNodeGen.java:45)
    at com.oracle.truffle.api.interop.InteropAccessNode.execute(InteropAccessNode.java:87)
    at com.oracle.truffle.api.interop.ForeignAccess.sendExecute(ForeignAccess.java:463)
    at com.oracle.truffle.polyglot.PolyglotExecuteNode.execute(PolyglotExecuteNode.java:89)
    at com.oracle.truffle.polyglot.FunctionProxyNode.executeImpl(HostInteropReflect.java:373)
    at com.oracle.truffle.polyglot.FunctionProxyNode.executeImpl(HostInteropReflect.java:341)
    at com.oracle.truffle.polyglot.HostRootNode.execute(HostRootNode.java:94)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:209)
    at com.oracle.truffle.polyglot.FunctionProxyHandler.invoke(HostInteropReflect.java:436)
    at com.sun.proxy.$Proxy31.apply(Unknown Source)
    at Main$.delayedEndpoint$Main$1(Main.scala:61)
    at Main$delayedInit$body.apply(Main.scala:7)
    at scala.Function0.apply$mcV$sp(Function0.scala:34)
    at scala.Function0.apply$mcV$sp$(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App.$anonfun$main$1$adapted(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at scala.App.main(App.scala:76)
    at scala.App.main$(App.scala:74)
    at Main$.main(Main.scala:7)
    at Main.main(Main.scala)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(ArrayList.java:422)
    at java.util.ArrayList.remove(ArrayList.java:499)
    at com.oracle.truffle.r.ffi.impl.common.JavaUpCallsRFFIImpl.Rf_unprotect(JavaUpCallsRFFIImpl.java:1600)
    at com.oracle.truffle.r.ffi.impl.upcalls.Rf_unprotectCall$Rf_unprotectCallFactory$1.execute(Rf_unprotectCall.java:54)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callDirect(OptimizedCallTarget.java:216)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.api.interop.InteropAccessNode.doCached(InteropAccessNode.java:206)
    at com.oracle.truffle.api.interop.InteropAccessNodeGen.executeImpl(InteropAccessNodeGen.java:35)
    at com.oracle.truffle.api.interop.InteropAccessNode.execute(InteropAccessNode.java:87)
    at com.oracle.truffle.api.interop.ForeignAccess.send(ForeignAccess.java:241)
    at com.oracle.truffle.nfi.impl.LibFFIClosure$CallClosureNode.execute(LibFFIClosure.java:159)
    at com.oracle.truffle.nfi.impl.LibFFIClosure$ObjectRetClosureRootNode.execute(LibFFIClosure.java:218)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:264)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:251)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:233)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:209)
    at com.oracle.truffle.nfi.impl.NFIContext.executePrimitive(Native Method)
    at com.oracle.truffle.nfi.impl.NFIContext.executePrimitive(NFIContext.java:280)
    at com.oracle.truffle.nfi.impl.LibFFISignature.execute(LibFFISignature.java:185)
    at com.oracle.truffle.nfi.impl.LibFFIFunctionMessageResolution$CachedExecuteNode.cachedSignature(LibFFIFunctionMessageResolution.java:90)
    at com.oracle.truffle.nfi.impl.LibFFIFunctionMessageResolutionFactory$CachedExecuteNodeGen.execute(LibFFIFunctionMessageResolutionFactory.java:38)
    at com.oracle.truffle.nfi.impl.LibFFIFunctionMessageResolution$ExecuteLibFFIFunctionNode.access(LibFFIFunctionMessageResolution.java:197)
    at com.oracle.truffle.nfi.impl.LibFFIFunctionMessageResolutionForeign$ExecuteLibFFIFunctionSubNode.accessWithTarget(LibFFIFunctionMessageResolutionForeign.java:124)
    at com.oracle.truffle.nfi.impl.LibFFIFunctionMessageResolutionForeignFactory$ExecuteLibFFIFunctionSubNodeGen.executeWithTarget(LibFFIFunctionMessageResolutionForeignFactory.java:39)
    at com.oracle.truffle.nfi.impl.LibFFIFunctionMessageResolutionForeign$ExecuteLibFFIFunctionSubNode$EXECUTERootNode.execute(LibFFIFunctionMessageResolutionForeign.java:146)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callProxy(OptimizedCallTarget.java:275)
    at org.graalvm.compiler.truffle.runtime.OptimizedCallTarget.callInlined(OptimizedCallTarget.java:229)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.callProxy(OptimizedDirectCallNode.java:84)
    at org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode.call(OptimizedDirectCallNode.java:68)
    at com.oracle.truffle.api.interop.InteropAccessNode.doCached(InteropAccessNode.java:206)
    at com.oracle.truffle.api.interop.InteropAccessNodeGen.executeImpl(InteropAccessNodeGen.java:35)
    at com.oracle.truffle.api.interop.InteropAccessNode.execute(InteropAccessNode.java:87)
    at com.oracle.truffle.api.interop.ForeignAccess.sendExecute(ForeignAccess.java:463)
    at com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_Call$TruffleNFI_InvokeCallNode.invokeCallCached(TruffleNFI_Call.java:97)
    at com.oracle.truffle.r.ffi.impl.nfi.TruffleNFI_CallFactory$TruffleNFI_InvokeCallNodeGen.execute(TruffleNFI_CallFactory.java:41)
    at com.oracle.truffle.r.runtime.ffi.CallRFFI$InvokeCallNode.dispatch(CallRFFI.java:41)
    at com.oracle.truffle.r.nodes.builtin.base.foreign.CallAndExternalFunctions$Dot.dispatch(CallAndExternalFunctions.java:971)
    at com.oracle.truffle.r.nodes.builtin.base.foreign.CallAndExternalFunctions$DotCall.callNamedFunctionWithPackage(CallAndExternalFunctions.java:718)
    at com.oracle.truffle.r.nodes.builtin.base.foreign.CallAndExternalFunctionsFactory$DotCallNodeGen.execute(CallAndExternalFunctionsFactory.java:95)
    at com.oracle.truffle.r.nodes.builtin.RBuiltinNode$Arg3.call(RBuiltinNode.java:200)
    at com.oracle.truffle.r.nodes.function.RCallNode$BuiltinCallNode.execute(RCallNode.java:1123)
    at com.oracle.truffle.r.nodes.function.RCallNode$FunctionDispatch.dispatch(RCallNode.java:905)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen$FunctionDispatchNodeGen.execute(RCallNodeGen.java:668)
    at com.oracle.truffle.r.nodes.function.RCallNode.call(RCallNode.java:274)
    at com.oracle.truffle.r.nodes.function.RCallNodeGen.execute(RCallNodeGen.java:161)
    at com.oracle.truffle.r.runtime.nodes.RNode.visibleExecute(RNode.java:74)
    at com.oracle.truffle.r.nodes.control.BlockNode.visibleExecute(BlockNode.java:88)
    at com.oracle.truffle.r.nodes.function.FunctionBodyNode.visibleExecute(FunctionBodyNode.java:58)
    at com.oracle.truffle.r.nodes.function.FunctionDefinitionNode.execute(FunctionDefinitionNode.java:280)
    ... 209 more
Caused by: Attached Guest Language Frames (10)

Process finished with exit code 1
steve-s commented 5 years ago

Hello Nathan,

it seems that we've seen this issue before and we believe that this time it is a problem on the side of R package Rcpp used by pdftools. The issue was reported here: https://github.com/RcppCore/Rcpp/issues/935. In the meantime as a workaround you can patch Rcpp sources:

--- a/inst/include/Rcpp/protection/Shelter.h
+++ b/inst/include/Rcpp/protection/Shelter.h
@@ -26,7 +26,7 @@ namespace Rcpp {
         Shelter() : nprotected(0){}

         inline SEXP operator()(SEXP x){
-            nprotected++;
+           if ( x != R_NilValue ) nprotected++;
             return Rcpp_protect(x) ;
         }

in case you're not that familiar with R ecosystem: you'll have to download the Rcpp sources (e.g., to ~/Rcpp), apply the patch and then install the patched Rcpp via R CMD INSTALL ~/Rcpp and then re-install pdftools via install.packages("pdftools") so that it's built with the new Rcpp headers.

With the patched version of Rcpp, the provided example gives me:

[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
<std::runtime_error in poppler_render_page(loadfile(pdf), page, dpi, opw, upw, antialiasing,     text_antialiasing): Invalid page.>
[1] "Yah, finished!"

which seems to be the same as GNU-R.

but it is a work around we were trying for other issues in RC11

if you can, please report those issues as well even if you have a workaround. It will be appreciated. (Including how you worked around the issue would be great too).

NRBPerdijk commented 5 years ago

The "other issues" for which this is a workaround can all be traced back to #49, so we expect them to disappear with the next GraalVM RC.

Thanks for the local fix of the RCCP-issue. Patching local sources and reinstalling pdftools does indeed make the problem go away! 👍

steve-s commented 5 years ago

FYI, we changed the behavior and FastR is now tolerant to unbalanced protect/unprotect, you only get a warning instead of an error, so if you don't mind that warning, you can use unpatched version of Rcpp.

NRBPerdijk commented 5 years ago

Good to know!