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

LibJVM: Start parsing class files #11500

Closed
wants to merge 2 commits into from

Conversation

noahhaasis
Copy link
Contributor

The ClassFileParser is able to parse simple classfiles into a ClassFile structure.
The parser successfully consumes the .class file of the most basic Java program:

class Main {
    static void main(String args[]) {}
}

There is still a lot missing but I want to have this overall structure reviewed before I flesh out the parser and start using the ClassFile interface in the Runtime.
I'm new to modern C++ so there's probably lots to improve.

One design decision I made, is that the ClassFile structure holds onto the buffer containing the contents of the .class file. This is because fields of the ClassFile structure point into the buffer e.g. for strings or bytecode.

Another design decision is using unions instead of inheritance to represent constants in the java constant pool.

The parser is not complete and the interface will change as the runtime
gets developed.
But the parser is already able to parse the classfile of a simple Java
program:
```java
class Main {
  public static void main(String[] args) {
  }
}

```
@noahhaasis noahhaasis marked this pull request as ready for review December 30, 2021 11:42
@caoimhebyrne
Copy link
Contributor

caoimhebyrne commented Dec 30, 2021

Looks like you're missing a CMakeLists.txt file for LibJVM

@awesomekling
Copy link
Contributor

From our contributing guidelines:

When contributing to SerenityOS, make sure that the changes you wish to make are in line with the project direction. If you are not sure about this, open an issue first, so we can discuss it.

I haven't seen any discussion about building a JVM anywhere. SerenityOS has nothing to do with Java, so why does it suddenly need a JVM?

@noahhaasis
Copy link
Contributor Author

From our contributing guidelines:

When contributing to SerenityOS, make sure that the changes you wish to make are in line with the project direction. If you are not sure about this, open an issue first, so we can discuss it.

I haven't seen any discussion about building a JVM anywhere. SerenityOS has nothing to do with Java, so why does it suddenly need a JVM?

I saw a single mention on the Discord

A: Do Serenity supports Java or nor yet?
B: There's no port nor custom implementation, so no.
C: You are more than welcome to implement stuff though! (Maybe dont start with the jvm...)

And I think it came up in office hours a few times, does Serenity run Minecraft, support Java ... with the typical answer, no but you could work on that.

But yes I understand that a second VM might not fit into Serenity and that nobody wants a dead library.
So should I open an issue or close the MR? It was a fun learning exercise over the holidays anyways :)

The constant pool now has its own class ConstantPool.
Also the invidivual constants now have nicer accesors which lookup their
indices in the given constant pool.
@awesomekling
Copy link
Contributor

If you want to build a JVM, I suggest doing it as a completely separate project from SerenityOS, as there is no natural need for Java anywhere in this system. :)

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

Successfully merging this pull request may close these issues.

3 participants