Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Truffle] NPE in Singleton.new #2814

Closed
bjfish opened this issue Apr 9, 2015 · 4 comments
Closed

[Truffle] NPE in Singleton.new #2814

bjfish opened this issue Apr 9, 2015 · 4 comments

Comments

@bjfish
Copy link
Contributor

bjfish commented Apr 9, 2015

There is one more error causing 2 of the singleton spec examples to fail with a null pointer error.

Error (I think the allocator is null in RubyClass):

java.lang.NullPointerException
    at org.jruby.truffle.runtime.core.RubyClass.allocate(RubyClass.java:135)
    at org.jruby.truffle.nodes.core.ClassNodes$AllocateNode.allocate(ClassNodes.java:51)
    at org.jruby.truffle.nodes.core.ClassNodesFactory$AllocateNodeFactory$AllocateRubyClassNode.executeAllocate(ClassNodesFactory.java:303)
    at org.jruby.truffle.nodes.core.ClassNodes$NewNode.doNewInstance(ClassNodes.java:87)
    at org.jruby.truffle.nodes.core.ClassNodes$NewNode.newInstance(ClassNodes.java:78)
    at org.jruby.truffle.nodes.core.ClassNodesFactory$NewNodeFactory$NewRubyClassUndefinedPlaceholderNode.executeChained0(ClassNodesFactory.java:637)
    at org.jruby.truffle.nodes.core.ClassNodesFactory$NewNodeFactory$NewPolymorphicNode.executeRubyBasicObject(ClassNodesFactory.java:755)
    at org.jruby.truffle.nodes.core.ClassNodesFactory$NewNodeFactory$NewPolymorphicNode.execute(ClassNodesFactory.java:731)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:83)
    at org.jruby.truffle.nodes.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:52)
    at org.jruby.truffle.nodes.RubyRootNode.execute(RubyRootNode.java:54)
    at com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:77)
    at com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:65)
    at org.jruby.truffle.nodes.dispatch.CachedBoxedDispatchNode.executeDispatch(CachedBoxedDispatchNode.java:145)
    at org.jruby.truffle.nodes.dispatch.UnresolvedDispatchNode.executeDispatch(UnresolvedDispatchNode.java:108)
    at org.jruby.truffle.nodes.dispatch.DispatchHeadNode.dispatch(DispatchHeadNode.java:53)
    at org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode.call(CallDispatchHeadNode.java:35)
    at org.jruby.truffle.nodes.RubyCallNode.execute(RubyCallNode.java:150)
    at org.jruby.truffle.nodes.objects.WriteInstanceVariableNode.execute(WriteInstanceVariableNode.java:102)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:83)
    at org.jruby.truffle.nodes.methods.RedoableNode.execute(RedoableNode.java:35)
    at org.jruby.truffle.nodes.methods.CatchReturnPlaceholderNode.execute(CatchReturnPlaceholderNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchNextNode.execute(CatchNextNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchRetryAsErrorNode.execute(CatchRetryAsErrorNode.java:32)
    at org.jruby.truffle.nodes.RubyRootNode.execute(RubyRootNode.java:54)
    at com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:77)
    at com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:65)
    at org.jruby.truffle.nodes.yield.CachedYieldDispatchNode.dispatchWithSelfAndBlock(CachedYieldDispatchNode.java:62)
    at org.jruby.truffle.nodes.yield.UninitializedYieldDispatchNode.dispatchWithSelfAndBlock(UninitializedYieldDispatchNode.java:71)
    at org.jruby.truffle.nodes.yield.UninitializedYieldDispatchNode.dispatchWithSelfAndBlock(UninitializedYieldDispatchNode.java:71)
    at org.jruby.truffle.nodes.yield.YieldDispatchHeadNode.dispatch(YieldDispatchHeadNode.java:34)
    at org.jruby.truffle.nodes.yield.YieldNode.execute(YieldNode.java:64)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:83)
    at org.jruby.truffle.nodes.control.EnsureNode.execute(EnsureNode.java:34)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:83)
    at org.jruby.truffle.nodes.methods.CatchBreakAsReturnNode.execute(CatchBreakAsReturnNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchReturnNode.execute(CatchReturnNode.java:39)
    at org.jruby.truffle.nodes.methods.CatchNextNode.execute(CatchNextNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchRetryAsErrorNode.execute(CatchRetryAsErrorNode.java:32)
    at org.jruby.truffle.nodes.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:52)
    at org.jruby.truffle.nodes.RubyRootNode.execute(RubyRootNode.java:54)
    at com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:77)
    at com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:65)
    at org.jruby.truffle.nodes.dispatch.CachedBoxedDispatchNode.executeDispatch(CachedBoxedDispatchNode.java:145)
    at org.jruby.truffle.nodes.dispatch.UnresolvedDispatchNode.executeDispatch(UnresolvedDispatchNode.java:108)
    at org.jruby.truffle.nodes.dispatch.DispatchHeadNode.dispatch(DispatchHeadNode.java:53)
    at org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode.call(CallDispatchHeadNode.java:35)
    at org.jruby.truffle.nodes.RubyCallNode.execute(RubyCallNode.java:150)
    at org.jruby.truffle.nodes.RubyNode.executeVoid(RubyNode.java:204)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:80)
    at org.jruby.truffle.nodes.methods.CatchBreakAsReturnNode.execute(CatchBreakAsReturnNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchReturnNode.execute(CatchReturnNode.java:39)
    at org.jruby.truffle.nodes.methods.CatchNextNode.execute(CatchNextNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchRetryAsErrorNode.execute(CatchRetryAsErrorNode.java:32)
    at org.jruby.truffle.nodes.methods.ExceptionTranslatingNode.execute(ExceptionTranslatingNode.java:52)
    at org.jruby.truffle.nodes.RubyRootNode.execute(RubyRootNode.java:54)
    at com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:77)
    at com.oracle.truffle.api.impl.DefaultDirectCallNode.call(DefaultDirectCallNode.java:65)
    at org.jruby.truffle.nodes.dispatch.CachedBoxedDispatchNode.executeDispatch(CachedBoxedDispatchNode.java:145)
    at org.jruby.truffle.nodes.dispatch.UnresolvedDispatchNode.executeDispatch(UnresolvedDispatchNode.java:108)
    at org.jruby.truffle.nodes.dispatch.DispatchHeadNode.dispatch(DispatchHeadNode.java:53)
    at org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode.call(CallDispatchHeadNode.java:35)
    at org.jruby.truffle.nodes.RubyCallNode.execute(RubyCallNode.java:150)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:83)
    at org.jruby.truffle.nodes.methods.CatchNextNode.execute(CatchNextNode.java:36)
    at org.jruby.truffle.nodes.methods.CatchReturnAsErrorNode.execute(CatchReturnAsErrorNode.java:37)
    at org.jruby.truffle.nodes.methods.CatchRetryAsErrorNode.execute(CatchRetryAsErrorNode.java:32)
    at org.jruby.truffle.nodes.methods.SetMethodDeclarationContext.execute(SetMethodDeclarationContext.java:46)
    at org.jruby.truffle.nodes.TopLevelRaiseHandler.execute(TopLevelRaiseHandler.java:32)
    at org.jruby.truffle.nodes.control.SequenceNode.execute(SequenceNode.java:83)
    at org.jruby.truffle.nodes.RubyRootNode.execute(RubyRootNode.java:54)
    at com.oracle.truffle.api.impl.DefaultCallTarget.call(DefaultCallTarget.java:77)
    at org.jruby.truffle.runtime.RubyContext.execute(RubyContext.java:251)
    at org.jruby.truffle.runtime.RubyContext.execute(RubyContext.java:240)
    at org.jruby.truffle.runtime.RubyContext.load(RubyContext.java:191)
    at org.jruby.truffle.TruffleBridgeImpl.execute(TruffleBridgeImpl.java:191)
    at org.jruby.truffle.TruffleBridgeImpl.execute(TruffleBridgeImpl.java:168)
    at org.jruby.Ruby.runInterpreter(Ruby.java:867)
    at org.jruby.Ruby.runInterpreter(Ruby.java:881)
    at org.jruby.Ruby.runNormally(Ruby.java:756)
    at org.jruby.Ruby.runFromMain(Ruby.java:573)
    at org.jruby.Main.doRunFromMain(Main.java:404)
    at org.jruby.Main.internalRun(Main.java:299)
    at org.jruby.Main.run(Main.java:226)
    at org.jruby.Main.main(Main.java:198)
rang.rb:26:in `new': internal implementation error - NullPointerException null org.jruby.truffle.runtime.core.RubyClass.allocate(RubyClass.java:135) (RubyTruffleError)
    from rang.rb:26:in `block in instance'
    from core:/core/rubinius/common/mutex.rb:34:in `synchronize'
    from rang.rb:24:in `instance'
    from rang.rb:53:in `<main>'

Here is a shortened example which causes the error:

module Singleton
  module SingletonClassMethods

    def clone # :nodoc:
      Singleton.__init__(super)
    end

    private

    def inherited(sub_klass)
      super
      Singleton.__init__(sub_klass)
    end
  end

  class << Singleton # :nodoc:
    def __init__(klass) # :nodoc:
      klass.instance_eval {
        @singleton__instance__ = nil
        @singleton__mutex__ = Mutex.new
      }
      def klass.instance # :nodoc:
        return @singleton__instance__ if @singleton__instance__
        @singleton__mutex__.synchronize {
          return @singleton__instance__ if @singleton__instance__
          @singleton__instance__ = new()
        }
        @singleton__instance__
      end
      klass
    end

    private

    # extending an object with Singleton is a bad idea
    undef_method :extend_object

    def included(klass)
      super
      klass.private_class_method :new, :allocate
      klass.extend SingletonClassMethods
      Singleton.__init__(klass)
    end

  end
end
class MyClass
    include Singleton
end
class MyClassChild < MyClass
end

MyClassChild.clone.instance
@chrisseaton
Copy link
Contributor

What you have exceptions can you include the full Java backtrace, with -Xtruffle.exceptions.print_java=true

@chrisseaton chrisseaton added this to the truffle-dev milestone Apr 9, 2015
@bjfish
Copy link
Contributor Author

bjfish commented Apr 9, 2015

@chrisseaton Thanks, added the full stacktrace.

@eregon eregon closed this as completed in e92392d Apr 14, 2015
@eregon
Copy link
Member

eregon commented Apr 14, 2015

The NPE is fixed, but a Class copy is not really good right now as it does not preserve enough info.

@eregon
Copy link
Member

eregon commented Apr 14, 2015

ff65fb8 should improve the class and module copies.

@enebo enebo added this to the Invalid or Duplicate milestone Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants