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

add-watch segfault #1338

Closed
frenchy64 opened this issue Aug 15, 2022 · 7 comments
Closed

add-watch segfault #1338

frenchy64 opened this issue Aug 15, 2022 · 7 comments

Comments

@frenchy64
Copy link

version

babashka v0.9.161

platform

Intel MacBook Pro, macOS 12.4

problem

Any use of clojure.core/add-watch results in a segfault on my machine.

repro

Babashka v0.9.161 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (def a 1)
#'user/a
user=> (add-watch #'a :prn prn)

[ [ SubstrateSegfaultHandler caught a segfault in thread 0x00007fcd9a704b40 ] ]
siginfo: si_signo: 11, si_code: 1, si_addr: 0x0000000000e89798

Current timestamp: 1660535872242

General purpose register values:
  RAX 0x0000000000e89798 is an unknown value
  RBX 0x0000000000e89798 is an unknown value
  RCX 0x00000001144b4420 points into the image heap (writable references)
    is an object of type clojure.lang.Keyword
  RDX 0x00000000fb4ce566 is an unknown value
  RBP 0x0000000000d99610 is an unknown value
  RSI 0x0000000000000000
  RDI 0x0000000115417fb0 points into an aligned TLAB chunk of thread 0x00007fcd9a704b40
    is an object of type [Ljava.lang.Object;
  RSP 0x00007ff7b19be058 points into the stack for thread 0x00007fcd9a704b40
  R8  0x0000000114626408 points into the image heap (writable references)
    is an object of type sci.impl.io$prn
  R9  0x0000000115607560 points into an aligned TLAB chunk of thread 0x00007fcd9a704b40
    is an object of type clojure.lang.Box
  R10 0x0000000115607560 points into an aligned TLAB chunk of thread 0x00007fcd9a704b40
    is an object of type clojure.lang.Box
  R11 0x0000000000000206 is an unknown value
  R12 0x00000001135ca0d0 points into the image heap (read-only relocatables)
    is the hub of clojure.core$maybe_min_hash$iter__6987__6993$fn__6994$iter__6989__6995
  R13 0x00000000029ff0f0 is an unknown value
  R14 0x0000000112c00000 is the heap base
  R15 0x00007fcd9a704b40 is a thread
  EFL 0x0000000000010202 is an unknown value
  RIP 0x0000000000e89798 is an unknown value

Printing Instructions (ip=0x0000000000e89798):
  0x0000000000e89778:
  [ [ SubstrateSegfaultHandler caught a segfault in thread 0x00007fcd9a704b40 ] ]
  siginfo: si_signo: 11, si_code: 1, si_addr: 0x0000000000e89778


Printing Instructions (ip=0x0000000000e89798):
  0x0000000000e89788:
  [ [ SubstrateSegfaultHandler caught a segfault in thread 0x00007fcd9a704b40 ] ]
  siginfo: si_signo: 11, si_code: 1, si_addr: 0x0000000000e89788


Printing Instructions (ip=0x0000000000e89798):
  0x0000000000e89798:
  [ [ SubstrateSegfaultHandler caught a segfault in thread 0x00007fcd9a704b40 ] ]
  siginfo: si_signo: 11, si_code: 1, si_addr: 0x0000000000e89798


Top of stack (sp=0x00007ff7b19be058):
  0x00007ff7b19be058: 0x000000010e9ea67f 0x00000001144b2e68
  0x00007ff7b19be068: 0x0000000115607520 0x0000000115417fb0
  0x00007ff7b19be078: 0x000000010ed2340d 0x0000000000d99610
  0x00007ff7b19be088: 0x00000001144b4420 0x0000000115607560
  0x00007ff7b19be098: 0x0000000115417ff0 0x0000000115418020
  0x00007ff7b19be0a8: 0x000000010e98c4ee 0x000000010ea810c0
  0x00007ff7b19be0b8: 0x000000010e9dea3d 0x00000001144b4420
  0x00007ff7b19be0c8: 0x0000000114626408 0x0000000115418020
  0x00007ff7b19be0d8: 0x000000010e766de6 0x0000000112c00000
  0x00007ff7b19be0e8: 0x00000000027ef4b8 0x0000000115418020
  0x00007ff7b19be0f8: 0x000000010e766d3c 0x0000000115418020
  0x00007ff7b19be108: 0x0000000110193048 0x00000001155fb500
  0x00007ff7b19be118: 0x00000001144f6eb0 0x0000000115418020
  0x00007ff7b19be128: 0x00000001144b4420 0x0000000114626408
  0x00007ff7b19be138: 0x000000010feeb3b0 0x000000010e79dcf0
  0x00007ff7b19be148: 0x00000001144b4420 0x0000000115418020
  0x00007ff7b19be158: 0x000000000158f200 0x000000011418f200
  0x00007ff7b19be168: 0x0000000113d56090 0x00000001155fc840
  0x00007ff7b19be178: 0x00000001155fd560 0x00000001155fd448
  0x00007ff7b19be188: 0x000000011003e80b 0x00000001155fb8a8
  0x00007ff7b19be198: 0x00000001145f0ec0 0x00000001155fd448
  0x00007ff7b19be1a8: 0x00000001155fc840 0x00000001155fc5c8
  0x00007ff7b19be1b8: 0x00000000029fc3e8 0x00000001155fc3e8
  0x00007ff7b19be1c8: 0x00000001155fd560 0x00000001155fb530
  0x00007ff7b19be1d8: 0x0000000115396130 0x00000001155fb8a8
  0x00007ff7b19be1e8: 0x000000010e66a764 0x000000045bea3bc0
  0x00007ff7b19be1f8: 0x000000010ea81ab1 0x000000011418e780
  0x00007ff7b19be208: 0x000000000158e780 0x0000000112c00000
  0x00007ff7b19be218: 0x0000000114188000 0x0000000001588000
  0x00007ff7b19be228: 0x0000000112c00000 0x0000000114198980
  0x00007ff7b19be238: 0x0000000001598980 0x0000000115418020
  0x00007ff7b19be248: 0x0000000114193040 0x00000001141408c0

Top frame info:
  Does not look like a Java Frame. Use JavaFrameAnchors to find LastJavaSP:

Threads:
  0x00007fcd9b004300 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "Signal Dispatcher" - 0x000000011500a708, daemon, stack(0x0000700004dee000,0x0000700004e6e000)
  0x00007fcd9b0041c0 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "Reference Handler" - 0x0000000113e30e40, daemon, stack(0x0000700004d6b000,0x0000700004deb000)
  0x00007fcd9a704b40 STATUS_IN_JAVA (PREVENT_VM_FROM_REACHING_SAFEPOINT) "main" - 0x0000000113e30d90, stack(0x00007ff7b11c0000,0x00007ff7b19c0000)

VM thread locals for the failing thread 0x00007fcd9a704b40:
  0 (8 bytes): JNIThreadLocalEnvironment.jniFunctions = (bytes)
    0x00007fcd9a704b40: 0x000000011355e010
  8 (8 bytes): StackOverflowCheckImpl.stackBoundaryTL = (Word) 1 (0x0000000000000001)
  16 (4 bytes): Safepoint.safepointRequested = (int) 2146863689 (0x7ff68a49)
  20 (4 bytes): StatusSupport.statusTL = (int) 1 (0x00000001)
  24 (32 bytes): ThreadLocalAllocation.regularTLAB = (bytes)
    0x00007fcd9a704b58: 0x0000000115600000 0x0000000115700000
    0x00007fcd9a704b68: 0x0000000115607580 0x0000000000000000
  56 (8 bytes): PlatformThreads.currentThread = (Object) java.lang.Thread (0x0000000113e30d90)
  64 (8 bytes): JavaFrameAnchors.lastAnchor = (Word) 0 (0x0000000000000000)
  72 (8 bytes): AccessControlContextStack = (Object) java.util.ArrayDeque (0x000000011500aa88)
  80 (8 bytes): ExceptionUnwind.currentException = (Object) null
  88 (8 bytes): IdentityHashCodeSupport.hashCodeGeneratorTL = (Object) java.util.SplittableRandom (0x00000001153020d0)
  96 (8 bytes): IsolatedCompileClient.currentClient = (Object) null
  104 (8 bytes): IsolatedCompileContext.currentContext = (Object) null
  112 (8 bytes): JNIObjectHandles.handles = (Object) com.oracle.svm.core.handles.ThreadLocalHandles (0x00000001150011f0)
  120 (8 bytes): JNIThreadLocalPendingException.pendingException = (Object) null
  128 (8 bytes): JNIThreadLocalPinnedObjects.pinnedObjectsListHead = (Object) null
  136 (8 bytes): JNIThreadOwnedMonitors.ownedMonitors = (Object) null
  144 (8 bytes): NoAllocationVerifier.openVerifiers = (Object) null
  152 (8 bytes): ThreadingSupportImpl.activeTimer = (Object) null
  160 (8 bytes): SubstrateDiagnostics.threadOnlyAttachedForCrashHandler = (bytes)
    0x00007fcd9a704be0: 0x0000000000000000
  168 (8 bytes): ThreadLocalAllocation.allocatedBytes = (Word) 4177688 (0x00000000003fbf18)
  176 (8 bytes): VMThreads.IsolateTL = (Word) 4609540096 (0x0000000112c00000)
  184 (8 bytes): VMThreads.OSThreadHandleTL = (Word) 4840195584 (0x00000001207f8600)
  192 (8 bytes): VMThreads.OSThreadIdTL = (Word) 4840195584 (0x00000001207f8600)
  200 (8 bytes): VMThreads.StackBase = (Word) 140701813440512 (0x00007ff7b19c0000)
  208 (8 bytes): VMThreads.StackEnd = (Word) 140701805051904 (0x00007ff7b11c0000)
  216 (8 bytes): VMThreads.StartedByCurrentIsolate = (bytes)
    0x00007fcd9a704c18: 0x0000000000000000
  224 (8 bytes): VMThreads.nextTL = (Word) 0 (0x0000000000000000)
  232 (8 bytes): VMThreads.unalignedIsolateThreadMemoryTL = (Word) 140521036073760 (0x00007fcd9a704b20)
  240 (4 bytes): ActionOnExitSafepointSupport.actionTL = (int) 0 (0x00000000)
  244 (4 bytes): ActionOnTransitionToJavaSupport.actionTL = (int) 0 (0x00000000)
  248 (4 bytes): ImplicitExceptions.implicitExceptionsAreFatal = (int) 0 (0x00000000)
  252 (4 bytes): StackOverflowCheckImpl.yellowZoneStateTL = (int) 2130640638 (0x7efefefe)
  256 (4 bytes): StatusSupport.safepointBehaviorTL = (int) 1 (0x00000001)
  260 (4 bytes): ThreadingSupportImpl.currentPauseDepth = (int) 0 (0x00000000)

No VMOperation in progress

The 15 most recent VM operation status changes (oldest first):

Counters:

Java frame anchors for the failing thread 0x00007fcd9a704b40:
  No anchors

Stacktrace for the failing thread 0x00007fcd9a704b40:
  SP 0x00007ff7b19be058 IP 0x0000000000e89798  IP is not within Java code. Aborting stack trace printing.

  WARNING: stack pointer is NOT aligned to 16 bytes. Starting a stack walk in the most likely caller instead.
  SP 0x00007ff7b19be060 IP 0x000000010e9ea67f  [image code] clojure.lang.PersistentHashMap.assoc(PersistentHashMap.java:143)
  SP 0x00007ff7b19be0b0 IP 0x000000010e98c4ee  [image code] clojure.lang.ARef.addWatch(ARef.java:63)
  SP 0x00007ff7b19be0e0 IP 0x000000010e766de6  [image code] clojure.core$add_watch.invokeStatic(core.clj:2177)
  SP 0x00007ff7b19be100 IP 0x000000010e766d3c  [image code] clojure.core$add_watch.invoke(core.clj:2161)
  SP 0x00007ff7b19be110 IP 0x0000000110193048  [image code] sci.lang.Var.invoke(lang.cljc:180)
  SP 0x00007ff7b19be140 IP 0x000000010feeb3b0  [image code] sci.impl.analyzer$return_call$reify__5215.eval(analyzer.cljc:1205)
  SP 0x00007ff7b19be190 IP 0x000000011003e80b  [image code] sci.impl.interpreter$eval_form.invokeStatic(interpreter.cljc:39)
  SP 0x00007ff7b19be1f0 IP 0x000000010e66a764  [image code] babashka.impl.repl$repl$fn__27497.invoke(repl.clj:74)
  SP 0x00007ff7b19be280 IP 0x000000010e5aeceb  [image code] babashka.impl.clojure.main$repl$read_eval_print__13228.invoke(main.clj:103)
  SP 0x00007ff7b19be2c0 IP 0x000000010e5ae9fc  [image code] babashka.impl.clojure.main$repl$fn__13233.invoke(main.clj:126)
  SP 0x00007ff7b19be2e0 IP 0x000000010e5b0014  [image code] babashka.impl.clojure.main$repl.invokeStatic(main.clj:126)
  SP 0x00007ff7b19be3b0 IP 0x000000010e66b41f  [image code] babashka.impl.repl$repl.invokeStatic(repl.clj:86)
  SP 0x00007ff7b19be410 IP 0x000000010e66d249  [image code] babashka.impl.repl$start_repl_BANG_.invokeStatic(repl.clj:88)
  SP 0x00007ff7b19be410 IP 0x000000010e66d249  [image code] babashka.impl.repl$start_repl_BANG_.invoke(repl.clj:88)
  SP 0x00007ff7b19be420 IP 0x000000010e66d2f5  [image code] babashka.impl.repl$start_repl_BANG_.invokeStatic(repl.clj:89)
  SP 0x00007ff7b19be430 IP 0x000000010e6a84de  [image code] babashka.main$exec.invokeStatic(main.clj:927)
  SP 0x00007ff7b19be5e0 IP 0x000000010e6ac965  [image code] babashka.main$main.invokeStatic(main.clj:1052)
  SP 0x00007ff7b19be650 IP 0x000000010e6ac189  [image code] babashka.main$main.doInvoke(main.clj:1027)
  SP 0x00007ff7b19be660 IP 0x000000010ea2e00c  [image code] clojure.lang.RestFn.invoke(RestFn.java:397)
  SP 0x00007ff7b19be680 IP 0x000000010e97938b  [image code] clojure.lang.AFn.applyToHelper(AFn.java:152)
  SP 0x00007ff7b19be7d0 IP 0x000000010ea27d1a  [image code] clojure.lang.RestFn.applyTo(RestFn.java:132)
  SP 0x00007ff7b19be930 IP 0x000000010e76a858  [image code] clojure.core$apply.invokeStatic(core.clj:667)
  SP 0x00007ff7b19be950 IP 0x000000010e69a3e1  [image code] babashka.main$_main.invokeStatic(main.clj:1085)
  SP 0x00007ff7b19be9e0 IP 0x000000010e69a1c9  [image code] babashka.main$_main.doInvoke(main.clj:1077)
  SP 0x00007ff7b19be9f0 IP 0x000000010ea2e00c  [image code] clojure.lang.RestFn.invoke(RestFn.java:397)
  SP 0x00007ff7b19bea10 IP 0x000000010e97938b  [image code] clojure.lang.AFn.applyToHelper(AFn.java:152)
  SP 0x00007ff7b19beb60 IP 0x000000010ea27d1a  [image code] clojure.lang.RestFn.applyTo(RestFn.java:132)
  SP 0x00007ff7b19becc0 IP 0x000000010e6bb230  [image code] babashka.main.main(Unknown Source)
  SP 0x00007ff7b19bece0 IP 0x000000010ec6b557  [image code] com.oracle.svm.core.JavaMainWrapper.runCore0(JavaMainWrapper.java:166)
  SP 0x00007ff7b19bed00 IP 0x000000010ec6b305  [image code] com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:130)
  SP 0x00007ff7b19bed00 IP 0x000000010ec6b305  [image code] com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:214)
  SP 0x00007ff7b19bed30 IP 0x000000010ecc1e1b  [image code] com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(IsolateEnterStub.java:0)

VM mutexes:
  mutex "thread" is unlocked.
  mutex "referencePendingList" is unlocked.
  mutex "mainVMOperationControlWorkQueue" is unlocked.

AOT compiled code is mapped at 0x000000010e543000 - 0x000000011078b56f

Heap settings and statistics:
  Supports isolates: true
  Heap base: 0x0000000112c00000
  Object reference size: 8
  Aligned chunk size: 1048576
  Incremental collections: 0
  Complete collections: 0

Native image heap boundaries:
  ReadOnly Primitives: 0x0000000112d01028 - 0x000000011319c050
  ReadOnly References: 0x000000011319c050 - 0x000000011355dac8
  ReadOnly Relocatables: 0x000000011355e000 - 0x0000000113bf4438
  Writable Primitives: 0x0000000113bf5000 - 0x0000000113d47130
  Writable References: 0x0000000113d47130 - 0x000000011466b688
  Writable Huge: 0x0000000114700030 - 0x00000001147f9050
  ReadOnly Huge: 0x00000001147fa030 - 0x0000000114f550b8

Heap:
  Young generation:
    Eden:
      edenSpace:
        aligned: 0/0 unaligned: 0/0
    Survivors:
      Survivor-1 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-1 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-2 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-2 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-3 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-3 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-4 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-4 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-5 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-5 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-6 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-6 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-7 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-7 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-8 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-8 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-9 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-9 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-10 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-10 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-11 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-11 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-12 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-12 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-13 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-13 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-14 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-14 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-15 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-15 To:
        aligned: 0/0 unaligned: 0/0
  Old generation:
    oldFromSpace:
      aligned: 0/0 unaligned: 0/0
    oldToSpace:
      aligned: 0/0 unaligned: 0/0

  Unused:
    aligned: 0/0

Segfault detected, aborting process. Use runtime option -R:-InstallSegfaultHandler if you don't want to use SubstrateSegfaultHandler.

expected behavior

@borkdude
Copy link
Collaborator

borkdude commented Aug 15, 2022 via email

@borkdude
Copy link
Collaborator

Having said that, how important is it to have this feature in bb? I've personally never used add-watch on vars and it will incur some performance hit every time a var is defined.

@frenchy64
Copy link
Author

frenchy64 commented Aug 15, 2022 via email

@borkdude
Copy link
Collaborator

OK, then for now I think the short term solution is to implement the expected interface on sci.lang.Var but throw a not implemented error instead of segfaulting. I noticed segfaults can happen with graal on incomplete protocol/interface implementations (in the host).

@borkdude
Copy link
Collaborator

How is this problem solved in normal Clojure btw?

@frenchy64
Copy link
Author

frenchy64 commented Aug 15, 2022 via email

@frenchy64
Copy link
Author

How is this problem solved in normal Clojure btw?

FWIW it occurred to me an extra indirection would allow instrumentation of protocol methods in babashka:

(defprotocol Foo (foo [this]))
=>
...
(defmulti __bb__foo ...)
(defn foo [this]
  (__bb__foo this))

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

2 participants