Skip to content

Provide java.lang.Terminator.setup() via --install-exit-handlers #2393

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

Merged
merged 3 commits into from
Apr 27, 2020
Merged

Provide java.lang.Terminator.setup() via --install-exit-handlers #2393

merged 3 commits into from
Apr 27, 2020

Conversation

olpaw
Copy link
Member

@olpaw olpaw commented Apr 24, 2020

This PR provides a fix for #1592

Testing with

public class Main {
    public static void main(String[] args) {
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Shutdown happens!");
        }));
        
        try {
            System.out.println("Zzzzzzz.....");
            Thread.sleep(Long.MAX_VALUE);
        } catch (InterruptedException e) {
            System.out.println("Good morning!");
            e.printStackTrace();
        }
    }
}

shows an image size increase of 48Kb when native-image --install-exit-handlers is used (from 6,802,048 bytes to 6,850,976 bytes)

@olpaw
Copy link
Member Author

olpaw commented Apr 27, 2020

@pejovica reminded me that there is java.lang.Terminator. That is exactly what we should use here.

@olpaw olpaw requested a review from pejovica April 27, 2020 09:47
@olpaw olpaw changed the title Implement SIGHUP/SIGINT/SIGTERM exit handlers for executable images Provide java.lang.Terminator.setup() via --install-exit-handlers Apr 27, 2020
@olpaw
Copy link
Member Author

olpaw commented Apr 27, 2020

Arrg calling the code from java.lang.Terminator.setup() does not work. Investigating ...

@pejovica
Copy link
Member

You need to reset java.lang.Terminator.handler field, or you could reuse com.oracle.svm.enterprise.pgo.substitutions.Target_java_lang_Terminator isntead.

@olpaw
Copy link
Member Author

olpaw commented Apr 27, 2020

Tested if this also works on Windows

C:\Users\pwoegere\OLabs\graal\substratevm>main.exe
Zzzzzzz.....
[CTRL-C]
Shutdown happens!

LGTM

@olpaw olpaw self-assigned this Apr 27, 2020
Copy link
Member

@pejovica pejovica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nicely done!

@christianwimmer christianwimmer added this to the 20.1 milestone Apr 27, 2020
@graalvmbot graalvmbot merged commit 2cd8551 into oracle:master Apr 27, 2020
@olpaw olpaw deleted the paw/GR-6033 branch April 28, 2020 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants