mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-21 09:01:56 -07:00
[Code cleanup] Unnecessary codes, JVM launch types
This commit is contained in:
parent
ffa6d7d0d7
commit
7c0f688f89
5 changed files with 39 additions and 170 deletions
|
|
@ -4,6 +4,4 @@ public final class VMLauncher {
|
||||||
private VMLauncher() {
|
private VMLauncher() {
|
||||||
}
|
}
|
||||||
public static native int launchJVM(String[] args);
|
public static native int launchJVM(String[] args);
|
||||||
|
|
||||||
public static native int createLaunchMainJVM(String[] vmArgs, String mainClass, String[] mainArgs);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ public class InstallModActivity extends LoggableActivity {
|
||||||
System.out.println(Arrays.toString(javaArgList.toArray(new String[0])));
|
System.out.println(Arrays.toString(javaArgList.toArray(new String[0])));
|
||||||
|
|
||||||
//JREUtils.redirectStdio(false);
|
//JREUtils.redirectStdio(false);
|
||||||
JREUtils.setJavaEnvironment(this, Tools.LAUNCH_TYPE);
|
JREUtils.setJavaEnvironment(this);
|
||||||
JREUtils.initJavaRuntime();
|
JREUtils.initJavaRuntime();
|
||||||
JREUtils.chdir(Tools.MAIN_PATH);
|
JREUtils.chdir(Tools.MAIN_PATH);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,21 +150,21 @@ public class JREUtils
|
||||||
LD_LIBRARY_PATH = ldLibraryPath.toString();
|
LD_LIBRARY_PATH = ldLibraryPath.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setJavaEnvironment(Context ctx, int launchType) throws Throwable {
|
public static void setJavaEnvironment(Context ctx) throws Throwable {
|
||||||
setEnvironment(launchType, "JAVA_HOME", Tools.homeJreDir);
|
setEnvironment("JAVA_HOME", Tools.homeJreDir);
|
||||||
setEnvironment(launchType, "HOME", Tools.MAIN_PATH);
|
setEnvironment("HOME", Tools.MAIN_PATH);
|
||||||
setEnvironment(launchType, "TMPDIR", ctx.getCacheDir().getAbsolutePath());
|
setEnvironment("TMPDIR", ctx.getCacheDir().getAbsolutePath());
|
||||||
setEnvironment(launchType, "LIBGL_MIPMAP", "3");
|
setEnvironment("LIBGL_MIPMAP", "3");
|
||||||
setEnvironment(launchType, "MESA_GLSL_CACHE_DIR", ctx.getCacheDir().getAbsolutePath());
|
setEnvironment("MESA_GLSL_CACHE_DIR", ctx.getCacheDir().getAbsolutePath());
|
||||||
setEnvironment(launchType, "LD_LIBRARY_PATH", LD_LIBRARY_PATH);
|
setEnvironment("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
|
||||||
setEnvironment(launchType, "PATH", Tools.homeJreDir + "/bin:" + Os.getenv("PATH"));
|
setEnvironment("PATH", Tools.homeJreDir + "/bin:" + Os.getenv("PATH"));
|
||||||
|
|
||||||
setEnvironment(launchType, "REGAL_GL_VENDOR", "Android");
|
setEnvironment("REGAL_GL_VENDOR", "Android");
|
||||||
setEnvironment(launchType, "REGAL_GL_RENDERER", "Regal");
|
setEnvironment("REGAL_GL_RENDERER", "Regal");
|
||||||
setEnvironment(launchType, "REGAL_GL_VERSION", "4.5");
|
setEnvironment("REGAL_GL_VERSION", "4.5");
|
||||||
|
|
||||||
setEnvironment(launchType, "AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth));
|
setEnvironment("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth));
|
||||||
setEnvironment(launchType, "AWTSTUB_HEIGHT", Integer.toString(CallbackBridge.windowHeight));
|
setEnvironment("AWTSTUB_HEIGHT", Integer.toString(CallbackBridge.windowHeight));
|
||||||
|
|
||||||
File customEnvFile = new File(Tools.MAIN_PATH, "custom_env.txt");
|
File customEnvFile = new File(Tools.MAIN_PATH, "custom_env.txt");
|
||||||
if (customEnvFile.exists() && customEnvFile.isFile()) {
|
if (customEnvFile.exists() && customEnvFile.isFile()) {
|
||||||
|
|
@ -173,7 +173,7 @@ public class JREUtils
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
// Not use split() as only split first one
|
// Not use split() as only split first one
|
||||||
int index = line.indexOf("=");
|
int index = line.indexOf("=");
|
||||||
setEnvironment(launchType, line.substring(0, index), line.substring(index + 1));
|
setEnvironment(line.substring(0, index), line.substring(index + 1));
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
@ -185,10 +185,7 @@ public class JREUtils
|
||||||
// return ldLibraryPath;
|
// return ldLibraryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setEnvironment(int launchType, String name, String value) throws Throwable {
|
private static void setEnvironment(String name, String value) throws Throwable {
|
||||||
if (launchType == Tools.LTYPE_PROCESS) {
|
|
||||||
Tools.mLaunchShell.writeToProcess("export " + name + "=" + value);
|
|
||||||
}
|
|
||||||
Os.setenv(name, value, true);
|
Os.setenv(name, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,6 @@ public final class Tools
|
||||||
"1.9"
|
"1.9"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public static final int LTYPE_PROCESS = 0;
|
|
||||||
public static final int LTYPE_INVOCATION = 1;
|
|
||||||
public static final int LTYPE_CREATEJAVAVM = 2;
|
|
||||||
public static final int LAUNCH_TYPE = LTYPE_INVOCATION;
|
|
||||||
|
|
||||||
public static ShellProcessOperation mLaunchShell;
|
public static ShellProcessOperation mLaunchShell;
|
||||||
private static int exitCode = 0;
|
private static int exitCode = 0;
|
||||||
public static void launchMinecraft(final LoggableActivity ctx, MCProfile.Builder profile, JMinecraftVersionList.Version versionInfo) throws Throwable {
|
public static void launchMinecraft(final LoggableActivity ctx, MCProfile.Builder profile, JMinecraftVersionList.Version versionInfo) throws Throwable {
|
||||||
|
|
@ -88,100 +82,40 @@ public final class Tools
|
||||||
|
|
||||||
String launchClassPath = generateLaunchClassPath(profile.getVersion());
|
String launchClassPath = generateLaunchClassPath(profile.getVersion());
|
||||||
System.out.println("Java Classpath: " + launchClassPath);
|
System.out.println("Java Classpath: " + launchClassPath);
|
||||||
if (LAUNCH_TYPE == LTYPE_CREATEJAVAVM) {
|
|
||||||
javaArgList.add("-Djava.class.path=" + launchClassPath);
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
if (LAUNCH_TYPE == LTYPE_PROCESS) {
|
|
||||||
javaArgList.add("-Dglfwstub.eglContext=" + Tools.getEGLAddress("Context", AndroidContextImplementation.context));
|
|
||||||
String eglDisplay = Tools.getEGLAddress("Display", AndroidContextImplementation.display);
|
|
||||||
if (eglDisplay.equals("1")) {
|
|
||||||
eglDisplay = Tools.getEGLAddress("Display", ((EGL10) EGLContext.getEGL()).eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY));
|
|
||||||
}
|
|
||||||
javaArgList.add("-Dglfwstub.eglDisplay=" + eglDisplay);
|
|
||||||
|
|
||||||
javaArgList.add("-Dglfwstub.eglSurfaceRead=" + Tools.getEGLAddress("Surface", AndroidContextImplementation.read));
|
getJavaArgs(ctx, javaArgList);
|
||||||
javaArgList.add("-Dglfwstub.eglSurfaceDraw=" + Tools.getEGLAddress("Surface", AndroidContextImplementation.draw));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
getJavaArgs(ctx, javaArgList);
|
javaArgList.add("-cp");
|
||||||
|
/*
|
||||||
|
if (versionInfo.mainClass.equals("net.minecraft.launchwrapper.Launch")) {
|
||||||
|
// Also preload LWJGL3 to fix crash on send input events
|
||||||
|
javaArgList.add(Tools.MAIN_PATH + "/lwjgl3/ClassWrapper.jar:" + getLWJGL3ClassPath());
|
||||||
|
javaArgList.add("ClassWrapper");
|
||||||
|
javaArgList.add(launchClassPath);
|
||||||
|
} else { */
|
||||||
|
javaArgList.add(getLWJGL3ClassPath() + ":" + launchClassPath);
|
||||||
|
// }
|
||||||
|
|
||||||
javaArgList.add("-cp");
|
javaArgList.add(versionInfo.mainClass);
|
||||||
/*
|
javaArgList.addAll(Arrays.asList(launchArgs));
|
||||||
if (versionInfo.mainClass.equals("net.minecraft.launchwrapper.Launch")) {
|
|
||||||
// Also preload LWJGL3 to fix crash on send input events
|
|
||||||
javaArgList.add(Tools.MAIN_PATH + "/lwjgl3/ClassWrapper.jar:" + getLWJGL3ClassPath());
|
|
||||||
javaArgList.add("ClassWrapper");
|
|
||||||
javaArgList.add(launchClassPath);
|
|
||||||
} else { */
|
|
||||||
javaArgList.add(getLWJGL3ClassPath() + ":" + launchClassPath);
|
|
||||||
// }
|
|
||||||
|
|
||||||
javaArgList.add(versionInfo.mainClass);
|
|
||||||
javaArgList.addAll(Arrays.asList(launchArgs));
|
|
||||||
/*
|
|
||||||
javaArgList.add("-cp");
|
|
||||||
javaArgList.add(launchClassPath);
|
|
||||||
javaArgList.add(versionInfo.mainClass);
|
|
||||||
javaArgList.addAll(Arrays.asList(launchArgs));
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LAUNCH_TYPE == LTYPE_PROCESS) {
|
|
||||||
mLaunchShell = new ShellProcessOperation(new ShellProcessOperation.OnPrintListener(){
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrintLine(String text) {
|
|
||||||
// ctx.appendToLog(text, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mLaunchShell.initInputStream(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
// can fix java?
|
// can fix java?
|
||||||
// setEnvironment("ORIGIN", Tools.homeJreDir + "/lib");
|
// setEnvironment("ORIGIN", Tools.homeJreDir + "/lib");
|
||||||
|
|
||||||
JREUtils.setJavaEnvironment(ctx, Tools.LAUNCH_TYPE);
|
JREUtils.setJavaEnvironment(ctx);
|
||||||
|
|
||||||
if (LAUNCH_TYPE == LTYPE_PROCESS) {
|
JREUtils.initJavaRuntime();
|
||||||
mLaunchShell.writeToProcess("cd $HOME");
|
JREUtils.chdir(Tools.MAIN_PATH);
|
||||||
|
|
||||||
mLaunchShell.writeToProcess(javaArgList.toArray(new String[0]));
|
if (new File(Tools.MAIN_PATH, "strace.txt").exists()) {
|
||||||
int exitCode = mLaunchShell.waitFor();
|
startStrace(android.os.Process.myTid());
|
||||||
if (exitCode != 0) {
|
|
||||||
Tools.showError(ctx, new ErrnoException("java", exitCode), false);
|
|
||||||
}
|
|
||||||
} else { // Type Invocation
|
|
||||||
// Is it need?
|
|
||||||
/*
|
|
||||||
Os.dup2(FileDescriptor.err, OsConstants.STDERR_FILENO);
|
|
||||||
Os.dup2(FileDescriptor.out, OsConstants.STDOUT_FILENO);
|
|
||||||
*/
|
|
||||||
|
|
||||||
JREUtils.initJavaRuntime();
|
|
||||||
JREUtils.chdir(Tools.MAIN_PATH);
|
|
||||||
|
|
||||||
if (new File(Tools.MAIN_PATH, "strace.txt").exists()) {
|
|
||||||
startStrace(android.os.Process.myTid());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LAUNCH_TYPE == LTYPE_CREATEJAVAVM) {
|
|
||||||
VMLauncher.createLaunchMainJVM(javaArgList.toArray(new String[0]), versionInfo.mainClass, launchArgs);
|
|
||||||
} else {
|
|
||||||
// Test
|
|
||||||
/*
|
|
||||||
VMLauncher.launchJVM(new String[]{
|
|
||||||
Tools.homeJreDir + "/bin/java",
|
|
||||||
"-invalidarg"
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
exitCode = VMLauncher.launchJVM(javaArgList.toArray(new String[0]));
|
|
||||||
ctx.appendlnToLog("Java Exit code: " + exitCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exitCode = VMLauncher.launchJVM(javaArgList.toArray(new String[0]));
|
||||||
|
ctx.appendlnToLog("Java Exit code: " + exitCode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ctx.runOnUiThread(new Runnable(){
|
ctx.runOnUiThread(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
||||||
|
|
@ -55,67 +55,7 @@ typedef jint JLI_Launch_func(int argc, char ** argv, /* main argc, argc */
|
||||||
jint ergo /* ergonomics class policy */
|
jint ergo /* ergonomics class policy */
|
||||||
);
|
);
|
||||||
|
|
||||||
static void logArgs(int argc, char** argv) {
|
|
||||||
/* BlockLauncher: disable logging
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < argc; i++) {
|
|
||||||
LOGD("arg[%d]: %s", i, argv[i]);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_createLaunchMainJVM(JNIEnv *env, jclass clazz, jobjectArray vmArgArr, jstring mainClassStr, jobjectArray mainArgArr) {
|
|
||||||
void *libjvm = dlopen("libjvm.so", RTLD_NOW + RTLD_GLOBAL);
|
|
||||||
if (libjvm == NULL) {
|
|
||||||
LOGE("dlopen failed to open libjvm.so (dlerror %s).", dlerror());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
JNI_CreateJavaVM_func *jl_JNI_CreateJavaVM = (JNI_CreateJavaVM_func *) dlsym(libjvm, "JNI_CreateJavaVM");
|
|
||||||
if (jl_JNI_CreateJavaVM == NULL) {
|
|
||||||
LOGE("dlsym failed to get JNI_CreateJavaVM (dlerror %s).", dlerror());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int vm_argc = (*env)->GetArrayLength(env, vmArgArr);
|
|
||||||
char **vm_argv = convert_to_char_array(env, vmArgArr);
|
|
||||||
|
|
||||||
int main_argc = (*env)->GetArrayLength(env, mainArgArr);
|
|
||||||
char **main_argv = convert_to_char_array(env, mainArgArr);
|
|
||||||
|
|
||||||
JavaVMInitArgs vm_args;
|
|
||||||
JavaVMOption options[vm_argc];
|
|
||||||
for (int i = 0; i < vm_argc; i++) {
|
|
||||||
options[i].optionString = vm_argv[i];
|
|
||||||
}
|
|
||||||
vm_args.version = JNI_VERSION_1_6;
|
|
||||||
vm_args.options = options;
|
|
||||||
vm_args.nOptions = vm_argc;
|
|
||||||
vm_args.ignoreUnrecognized = JNI_FALSE;
|
|
||||||
|
|
||||||
jint res = (jint) jl_JNI_CreateJavaVM(&runtimeJavaVMPtr, (void**)&runtimeJNIEnvPtr_JRE, &vm_args);
|
|
||||||
// delete options;
|
|
||||||
|
|
||||||
char *main_class_c = (*env)->GetStringUTFChars(env, mainClassStr, 0);
|
|
||||||
|
|
||||||
jclass mainClass = (*runtimeJNIEnvPtr_JRE)->FindClass(runtimeJNIEnvPtr_JRE, main_class_c);
|
|
||||||
jmethodID mainMethod = (*runtimeJNIEnvPtr_JRE)->GetStaticMethodID(runtimeJNIEnvPtr_JRE, mainClass, "main", "([Ljava/lang/String;)V");
|
|
||||||
|
|
||||||
// Need recreate jobjectArray to make JNIEnv is 'runtimeJNIEnvPtr_JRE'.
|
|
||||||
jobjectArray runtime_main_argv = convert_from_char_array(runtimeJNIEnvPtr_JRE, main_argv, main_argc);
|
|
||||||
(*runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod(runtimeJNIEnvPtr_JRE, mainClass, mainMethod, runtime_main_argv);
|
|
||||||
|
|
||||||
(*env)->ReleaseStringUTFChars(env, mainClassStr, main_class_c);
|
|
||||||
free_char_array(env, mainArgArr, main_argv);
|
|
||||||
free_char_array(env, vmArgArr, vm_argv);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static jint launchJVM(int argc, char** argv) {
|
static jint launchJVM(int argc, char** argv) {
|
||||||
logArgs(argc, argv);
|
|
||||||
|
|
||||||
void* libjli = dlopen("libjli.so", RTLD_LAZY | RTLD_GLOBAL);
|
void* libjli = dlopen("libjli.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||||
|
|
||||||
// Boardwalk: silence
|
// Boardwalk: silence
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue