[HN Gopher] Show HN: I spent my vacation writing a modern JVM as... ___________________________________________________________________ Show HN: I spent my vacation writing a modern JVM assembler Author : noone_youknow Score : 113 points Date : 2022-06-02 19:40 UTC (3 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | tornadofart wrote: | Impressive | noone_youknow wrote: | Thanks :) | noone_youknow wrote: | I had a lot of fun doing this, and along the way I learned a lot | about writing Gradle and IntelliJ plugins, and I hope others | might find this fun too :) | jpgvm wrote: | This is awesome. | | I have been toying with writing my own little JVM language (for | education purposes) and this could go a long way to making that a | bunch easier. | | Thanks for sharing! | hashmash wrote: | For the code generation phase, it might be easier to bypass | emitting a text-based assembly format and just use the ASM | library directly. If you want something easier, I wrote a code | generation library specifically for that purpose: | https://github.com/cojen/Maker It also includes an example | "Mini-C" language compiler. | noone_youknow wrote: | Awesome! I started this for educational purposes too, but if it | turns out to be useful then I'll be very happy! Hope it turns | out that way (and let me know if there's anything else you need | to make it useful! :) ) | kjeetgill wrote: | If you haven't heard of it already check out Truffle/graalvm | jpgvm wrote: | I have but Truffle was a bit further than I wanted to go for | now. If I wanted to build a production ready language it | would likely be my first choice though. | [deleted] | donsupreme wrote: | Bravo! you and I have very different way to decompress during a | vacation | noone_youknow wrote: | Haha yes, I'll admit there are probably better ways to | decompress :D | pdpi wrote: | I implemented a .class disassembler a while back by literally | reading the spec. It's surprisingly accessible. | noone_youknow wrote: | It really is. We've Sun to thank for that I think. | shrimpx wrote: | I built a .class interpreter for a college course (minus | reflection features). It was a ton of fun and ultimately | straightforward and simple. | dvt wrote: | Very cool! Reminds me of a little toy (and very unfinished) | project I worked on almost a decade ago (jeez, can't believe it's | been that long): https://github.com/dvx/jssembly | | Even our syntax is somewhat similar, though you're using plugins | for cleaner code which is an awesome idea. | noone_youknow wrote: | Awesome, I'm gonna have to take a good look at your project, | it's very interesting! Thanks :) | recursivedoubts wrote: | amazing! | | I will definitely discuss this in my compilers class, which | targets JVM bytecode as a back end! | noone_youknow wrote: | Awesome, thanks! Would love to hear if it turns out to be | interesting (or maybe even useful!) | tstack wrote: | I used to use jasmin to generate invalid code to test an old JVM. | I assume this has the same relaxed attitude that will let you | generate invalid code? | noone_youknow wrote: | It sure will, as an assembler it only does the bare minimum of | validation, so you should totally be able to generate "dodgy" | code and see if it works on older JVMs :) | ElijahLynn wrote: | These are the type of posts that make some of us noobs feel like | imposters, lol. (been coding webstack-ish for 10 years, fwiw, | can't even begin to write an assembler though :shrug:) | | Good on you though, we need inspiration too! And you definitely | should feel great about pulling that off! I am imaging it must | have been some really fantastic "flow" time! How did you feel | while writing it? Did you have family or friend distractions? Did | you feel super focused? What is that story? | | What are some of your focus patterns that you have identified? | What gets you motivated when you feel stuck? | brailsafe wrote: | If you had the skill and wherewithal to do something like this, | would you want to spend vacation doing it? I think it's neat, | but I'd probably want to get the hell away from my screen | [deleted] | cbm-vic-20 wrote: | "Let's just get this out of the way, shall we? | | {code here} " | | Thanks for doing that; I can't stand it when I go to a site for | something new and can't find what it actually looks like without | digging around. | [deleted] | noone_youknow wrote: | I couldn't agree more, I'm a big fan of "show me the code" | myself. | Strs2FillMyDrms wrote: | My question (if I may), When people say the bytecode is "platform | independent" I ask, exactly what platform is it being freed from? | | The compiler? The "cloud"? | | And this goes back to my lack of understanding of what | "publishing" a package means to Oracle and the ecosystem in | general. | | If I publish something on Maven, my guess is that it is | transformed into bytecode directly, so that when I pull my | package from a diff device the code can run. In this case if the | entire "internet" collapses then the only way to run my code | would be a flashdrive with the .java file run via a compiler... | unless there is a machine that has the JVM installed WITHOUT the | compiler... THEN the bytecode is useful... Am I correct? | wrs wrote: | It is independent of the processor architecture, and to a large | extent the operating system. (As opposed to an ordinary binary | executable, which depends on both.) | | The compiler turns Java source into bytecode. The JVM runs the | bytecode. The JVM doesn't need the compiler to run. | Strs2FillMyDrms wrote: | Thanks for your response. | | What I get from this is that the processor arch. Is dictated | by the compiler at compile time, and by writing to bytecode | directly we are skipping this. | | I thought the proc. arch. was established by the manufacturer | and was unavoidably implemented by the jni at runtime... | unless there is an interface on top of the jn-interface to | deal with the proc. But it seems absurd... why do this at | compile time? | playing_colours wrote: | Can anyone recommend a good source (book, articles) to learn Java | Bytecode? | noone_youknow wrote: | There's a "cookbook" document in the repo, but it's not very | comprehensive - I'd be more than happy to take PRs :) | https://github.com/roscopeco/jasm/blob/develop/docs/cookbook... | jfengel wrote: | There's a very old but still pretty effective book called | Programming for the Java Virtual Machine. Byte code is | remarkably stable. | | (Disclaimer: author) | topbanana wrote: | https://docs.oracle.com/javase/specs/jvms/se17/html/index.ht... | | and for .Net CIL https://www.ecma- | international.org/publications-and-standard... | rzzzt wrote: | The JVM spec is a bit dry but readable: | https://docs.oracle.com/javase/specs/jvms/se17/html/index.ht... | oh_sigh wrote: | I enjoyed reading about doing some things with the jvm which are | not possible through the java language - can anyone recommend a | page that goes further into that concept? | eternalban wrote: | ... checkcast java/lang/String areturn | | Looks like a typo. | newobj wrote: | no, areturn is a jvm opcode. | eternalban wrote: | ah. TIL. ___________________________________________________________________ (page generated 2022-06-02 23:00 UTC)