Live data from Hacker News

I have written a JVM in Rust

andreabergia.com

91–100 of 185 posts

Re: I have written a JVM in Rust

#91

I am curious if your ran into limitations due to the lifetimes on this signature fn execute_instruction( &mut self, vm: &mut Vm , call_stack: &mut CallStack , instruction: Instruction, ) -> Result , MethodCallFailed > When I try to add a lifetime to the `Err` variant of a `Result` and that lifetime is invariant (which it is due to `vm` and `call_stack`) it usually means that I can't use the question mark operator or…

EDIT: Looks like this is not an issue because the invariant lifetime 'a is not used for the mutable reference of vm or call_stack. So it's not the invariance that is the problem, but rather how Rust reasons about the lifetime of mutable references, which this avoids. In that case I don't understand what the point of 'a is on VM and CallStack. You can create[1][2] those with any unbounded lifetime (including 'static[3…

I wanted to express the fact that everything that gets allocated (call stack, frames, classes, and objects) is alive and valid until the "root" VM is, thus I used 'a more or less everywhere.

I also struggled with a got a ton of errors from the borrow checker initially, and I fixed many of those with a lot of explicit lifetimes, but it's not impossible that in some places they are unnecessary.

Re: I have written a JVM in Rust

#92

When I see such cool projects, I feel very overwhelmed. How do you get started with Rust and master basics to even attempt doing such a thing? Can OP explain?

Likewise. Not to go onto too much of tangent, but on a more personal note I've been generally struggling with this feeling a lot lately. I've been a professional software developer for almost 10 years, and I _know_ I'm competent (and not an impostor) as demonstrated by my current position and ability to ship things. However, lately after viewing developer blogs I become overwhelmed that I actually don't know enough a…

Well, you're probably comparing yourself against the top 1% of developers. It's okay to not be the very best, being in the top 30% of this field already is very rewarding.

Re: I have written a JVM in Rust

#93

That is pretty awesome! When I joined the Java effort in '92 (called Oak at the time) the group I was with was looking at writing a full OS in Java. The idea being that you could get to just the minimal set of things needed as "machine code" (aka native methods) you could reduce the attack surface of an embedded OS. (originally Java was targeted to run in things like TV's and other appliances). We were, of course, wo…

> writing a full OS in Java IMAO, Android kind of achieve that...kind of. They write lots of OS logics in Java (or Kotlin) but mixing lots of system services written in native code at the same time, interconnected by the famous (or infamous?) Bind IPC.

Embedded JVM is actually huge/pervasive and runs things as benign as the chip on your credit card.

Re: I have written a JVM in Rust

#94
post #93

Earlier quoted context omitted.

> writing a full OS in Java IMAO, Android kind of achieve that...kind of. They write lots of OS logics in Java (or Kotlin) but mixing lots of system services written in native code at the same time, interconnected by the famous (or infamous?) Bind IPC.

Embedded JVM is actually huge/pervasive and runs things as benign as the chip on your credit card.

After reading your comment I was surprised to find out that credit card chips have any processing capabilities whatsoever, which they apparently do, though at least according to gpt4, they are far too basic to run java/jvm. ?

Re: I have written a JVM in Rust

#95
post #93

Earlier quoted context omitted.

Embedded JVM is actually huge/pervasive and runs things as benign as the chip on your credit card.

After reading your comment I was surprised to find out that credit card chips have any processing capabilities whatsoever, which they apparently do, though at least according to gpt4, they are far too basic to run java/jvm. ?

It feels like that should be true, I get it. However Java Card is very real.

https://en.m.wikipedia.org/wiki/Java_Card

Re: I have written a JVM in Rust

#96

I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386 (486) AT clones. :-)

There's a no-std tutorial on how to write a demo kernel in Rust. https://os.phil-opp.com

osdev.org, sandpile.org, RBIL, and freevga. The biggest PITA is hardware support. There are many good vintage hardcopy books with recipes for things like reliable port IO and undocumented hardware tricks.

- Intel® 64 and IA-32 Architectures Software Developer’s Manual Combined Volumes: 1, 2A, 2B, 2C, 2D, 3A, 3B, 3C, 3D, and 4

- Microsoft MS-DOS Programmer's Reference (also includes real-mode BIOS calls)

- PC Interrupts

- Undocumented PC

- PC Intern

- Programmer's Guide To The EGA, VGA, And Super VGA Cards

- Graphics Programming Black Book Special Edition

Also, it's worth toying with advances in OS dev past the era of monolithic, microkernel, and hybrid.

1. Capability-based like seL4. It has a number of inherent performance and security advantages including capabilities and excellent IPC.

2. POSIX compatibility layer. Even embedded OSes without the concept of threads or processes can implement POSIX.

3. Hypervisor. They're much easier to add with intel's VT-[xd]. Failing that, fall back to emulation. Translational emulation is very performant.

4. Get good at generalizing interrupt handlers, making them fast, avoiding race conditions, and using lock-free patterns.

Also:

5. Rewriting or trapping unsupported instructions including x87 and MMX.

6. The failure of pure microkernel was the added complexity and management of sequencing multiple resources in a transactional manner. There are great theoretical security and operational advantages in microkernel architectures but they never caught on widely in a pure form.

Re: I have written a JVM in Rust

#98
post #93

Earlier quoted context omitted.

Embedded JVM is actually huge/pervasive and runs things as benign as the chip on your credit card.

After reading your comment I was surprised to find out that credit card chips have any processing capabilities whatsoever, which they apparently do, though at least according to gpt4, they are far too basic to run java/jvm. ?

Google appears to be significantly more useful than GPT-4 here. [1] is the third result for me for the query "credit card jvm". [2] is the second result and gives a direct (and more importantly, actually correct) answer. That post links to the Oracle documentation for Java Cards [3] which is the fourth result.

[1] https://en.m.wikipedia.org/wiki/Java_Card

[2] https://superuser.com/questions/362567/are-there-any-credit-...

[3] https://www.oracle.com/java/java-card/

All of this is just as easy as, if not easier than, using ChatGPT. It's unclear that such a tool even serves this purpose (retrieval of basic facts) adequately, so it should probably be avoided in the future.

Re: I have written a JVM in Rust

#99

Earlier quoted context omitted.

EDIT: Looks like this is not an issue because the invariant lifetime 'a is not used for the mutable reference of vm or call_stack. So it's not the invariance that is the problem, but rather how Rust reasons about the lifetime of mutable references, which this avoids. In that case I don't understand what the point of 'a is on VM and CallStack. You can create[1][2] those with any unbounded lifetime (including 'static[3…

I wanted to express the fact that everything that gets allocated (call stack, frames, classes, and objects) is alive and valid until the "root" VM is, thus I used 'a more or less everywhere. I also struggled with a got a ton of errors from the borrow checker initially, and I fixed many of those with a lot of explicit lifetimes, but it's not impossible that in some places they are unnecessary.

> I wanted to express the fact that everything that gets allocated (call stack, frames, classes, and objects) is alive and valid until the "root" VM is, thus I used 'a more or less everywhere.

That's not being expressed in the type system. The lifetime 'a is unbounded (meaning you can make it anything you want, including 'static) so anything that shares 'a can outlive the vm without rust complaining. it would be no different then if you removed 'a completely. If you wanted to ensure anything couldn't outlive the vm you could tie the lifetime to a reference to the vm, but then the vm can't hold those values (it would be a self-referential lifetime).

Re: I have written a JVM in Rust

#100
post #93

Earlier quoted context omitted.

Embedded JVM is actually huge/pervasive and runs things as benign as the chip on your credit card.

After reading your comment I was surprised to find out that credit card chips have any processing capabilities whatsoever, which they apparently do, though at least according to gpt4, they are far too basic to run java/jvm. ?

In what world did you convince yourself asking a chatbot was a source of real knowledge?

respect yourself enough to look at primary sources

Post reply on HN