Git Product home page Git Product logo

Comments (6)

rednaxelafx avatar rednaxelafx commented on June 3, 2024 1

Bypassing the public Java API to reach into the JVM for the stop() implementation isn't going to be portable, or supported in the long run. There is indeed no replacement for the stop() due to its semantics being problematic in the first place (i.e. skips proper unwinding of the stack)

The thing about being a REPL though is that you sort of have control over the compiler, at least for the part that was entered through the REPL. It might be possible to artificially add in a "blackhole"-style empty method at the backedges of all the loops to allow interrupts to have an anchor point to deliver to.

For reference, here's JDK8 HotSpot JVM/Linux's Thread.interrupt() and Thread.isInterrupted()'s underlying implementation.
https://github.com/openjdk/jdk8u-dev/blob/master/hotspot/src/os/linux/vm/os_linux.cpp#L4508-L4547
Essentially a fenced-write and a fenced-read on a boolean flag on the thread. So yeah the target thread won't notice this until it proactively checks the isInterrupted flag and does something about it.

from ammonite.

alexarchambault avatar alexarchambault commented on June 3, 2024

A problem here, IIUC, is that there's no real substitute for Thread.stop when users want to stop code like while (true) {} (or any code that keeps the CPU busy doing computation, rather than waiting for I/O and the like).

from ammonite.

lihaoyi avatar lihaoyi commented on June 3, 2024

I suspect it might be possible to re implement this using JNI, but I'm not familiar enough with the JVM C API to know for sure

from ammonite.

lihaoyi avatar lihaoyi commented on June 3, 2024

We don't actually have full control over the compiler due to Scala's binary dependencies; people pull in all sorts of Java/Scala jars from maven central or other projects those come pre-compiled.

We could do a bytecode rewrite on load using a JVM agent. That's pretty invasive, and may hurt performance, but I've done it before in https://github.com/lihaoyi/6858

from ammonite.

Jengamon avatar Jengamon commented on June 3, 2024

...SecurityManager is also on track for removal https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/SecurityManager.html

from ammonite.

lefou avatar lefou commented on June 3, 2024

...SecurityManager is also on track for removal https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/SecurityManager.html

Looks like a secret conspiracy to make threads immortal. 🤣

from ammonite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.