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

Java Class Library #7

Open
3 of 4 tasks
RobertObkircher opened this issue Apr 15, 2021 · 3 comments
Open
3 of 4 tasks

Java Class Library #7

RobertObkircher opened this issue Apr 15, 2021 · 3 comments
Labels

Comments

@RobertObkircher
Copy link
Owner

RobertObkircher commented Apr 15, 2021

Reuse OpenJDK or gnu classpath. Which native methdos do we have to implement ourselves? Can we link to a openjdk binary
for some things?

Step 1:

I think as a first step we should focus on making some classes from java/lang usable (Object, String).

  • lazy loading of classes
    Create a (bootstrap) classloader (or should it be named differently?).
    The classloader just keeps the zip files open but initially it only reads the index.
    Shoudl we only support normal files and jars or also jmods?

  • native methods (at least enough that we don't crash). Do we have to provide those for object?
    Currently some invoke instructions don't even check if a method is native.
    (dlopen the correct libraries)

  • strings
    We need to be able to turn a constan pool entry into an allocated string. Possibly with interning.

  • Threads?
    I don't know if we need some support for threads to run simple programs

Step 2 (maybe):

  • implement jni.h and jvm.h

  • create libjvm.so and copy it into our copy of the jdk. Should we move our copy of the system jdk into the build folder to avoid problems with multiple builds?

@RobertObkircher
Copy link
Owner Author

RobertObkircher commented Jun 5, 2021

Things I've been thinking about:

  • remove Reference and use pointers+inheritance for arrays, strings, class objects (see jni.h)

  • unify Value and jvalue?

  • classfile should have padding at the beginning so that we can use it as a java object

  • use a global variable for heap

  • use thread local storage for the current thread (and exceptions?)

  • the ability to push java values to the stack and increment by 1 or 2 depending on type descriptor

@RobertObkircher
Copy link
Owner Author

RobertObkircher commented Jun 5, 2021

For native methods we might need a library like https://dyncall.org/ We used libffi

@RobertObkircher
Copy link
Owner Author

Calling intiPhase1 requires Unsafe...

    BootstrapClassLoader::constants_mut().resolve_and_initialize(*thread);

    auto *system = BootstrapClassLoader::get().load_or_throw("java/lang/System");
    assert(system);
    jmethodID method = thread->jni_env->GetStaticMethodID((jclass) system, "initPhase1", "()V");
    assert(method);
    thread->jni_env->CallStaticVoidMethod((jclass) system, method);

    return 0;
}

extern "C" {
_JNI_IMPORT_OR_EXPORT_ void JNICALL
Java_jdk_internal_misc_Unsafe_registerNatives(JNIEnv *env, jclass clazz) {

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant