How to "throw out the new ZygoteInit.MethodAndArgsCaller" to clear the stacks of frames?

I am a beginner of Java and Android, and I was puzzled after reading the Zygote code init.

After Zygote expands the child process, in the end invokeStaticMain, he throws

throw new ZygoteInit.MethodAndArgsCaller(m, argv)

which is handled by a catch block that executes the child process ZygoteInit.main

catch (MethodAndArgsCaller caller) {
    caller.run();
}

Comments throw new ZygoteInit.MethodAndArgsCallersay that it will clear all the frames of the stack that were necessary when setting up the process.

But I can’t understand how frame stacks are cleared. I checked a related SO question, What are ZygoteInit calls? , but neither the question nor its answer explain the cleaning work.

Does an exception help with stack recycling?

+4
1

Java, return , void, .

, JVM ( Java) . , .

, , . , , , , java.io.IOException.

, , , , JVM . JVM catch, . , :

  • catch, JVM catch.

  • JVM public static void main(String[] args) , catch, main. , main - , . , . JRE (Java Runtime Environment) .

,

, , . 99,99% -, , 0,01% , , .

com.android.internal.os.ZygoteInit. :

/**
 * Helper exception class which holds a method and arguments and
 * can call them. This is used as part of a trampoline to get rid of
 * the initial process setup stack frames.
 */
public static class MethodAndArgsCaller extends Exception
       implements Runnable { ... }

" , ". , "" , , JVM , catch. .

, , ZygoteInit.MethodAndArgsCaller, - ZygoteInit class 'main, , -, . , com.android.internal.os.RuntimeInit, throws ZygoteInit.MethodAndArgsCaller . , , , MethodAndArgsCaller. , ?

Android, Java Zygote, (), , , Android. , , , .

+6

Source: https://habr.com/ru/post/1615165/


All Articles