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

Headless property is baked in, can no longer run heady #3064

Closed
kristofdho opened this issue Dec 13, 2020 · 8 comments · Fixed by #3068
Closed

Headless property is baked in, can no longer run heady #3064

kristofdho opened this issue Dec 13, 2020 · 8 comments · Fixed by #3068

Comments

@kristofdho
Copy link

Describe the issue
The awt invocation plugin causes the headless property to be stored at build-time, which means you can no longer switch between headless and heady execution at runtime. Since on windows, -Djava.awt.headless=true is set by native-image itself, this breaks any heady application.

The plugin seems to be directed at unix environments, as that's also the only awt support that's already added, so it might make sense to only conditionally add the plugin if we're targetting unix.

Additionally I think it's not preferable to have to decide at build-time if the application will run headless or heady.

The invocation plugin this is about:

/*
* To prevent AWT linkage error that happens with 'awt_headless' in headless mode, we eliminate
* native methods that depend on 'awt_xawt' library in the call-tree.
*/
private static void registerAWTPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, GraphicsEnvironment.class);
r.register0("isHeadless", new InvocationPlugin() {
@SuppressWarnings("unchecked")
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
boolean isHeadless = GraphicsEnvironment.isHeadless();
b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(isHeadless));
return true;
}
});
}

Steps to reproduce the issue

  • run any natively compiled windows app with -Djava.awt.headless=false and it will still be headless

Describe GraalVM and your environment:

  • GraalVM version: 72439a3 (as good as up to date with master)
  • JDK major version: 11
  • OS: Windows 10
  • Architecture: x64
@munishchouhan
Copy link
Contributor

@kristofdho please provide reproducer

@kristofdho
Copy link
Author

kristofdho commented Dec 15, 2020

file: BakedInHeadlessPoc.java

import java.awt.GraphicsEnvironment;

class BakedInHeadlessPoc {
    public static void main(String[] args) throws Exception {
		System.out.println(GraphicsEnvironment.isHeadless());
	}
}

compile & build:

javac BakedInHeadlessPoc.java
native-image -H:Name=BakedInHeadlessPoc -H:Class=BakedInHeadlessPoc --verbose --no-fallback

run compiled binary:

> BakedInHeadlessPoc.exe
true

> BakedInHeadlessPoc.exe -Djava.awt.headless=true
true

> BakedInHeadlessPoc.exe -Djava.awt.headless=false
true

expected output:

> BakedInHeadlessPoc.exe
false

> BakedInHeadlessPoc.exe -Djava.awt.headless=true
true

> BakedInHeadlessPoc.exe -Djava.awt.headless=false
false

marking GraphicsEnvironment for run-time initialization doesn't work and crashes the build, as the plugin appears to require it to be initialized at build-time.

suggested fix in #3068

@vjovanov vjovanov added this to the 21.1 milestone Dec 15, 2020
@kristofdho
Copy link
Author

Should this not be included in the 21.0 milestone as well? It is regression so it would make sense.
There is quite some stuff depending on this flag as well, like anything javafx, or awt functionality. I personally depend on both so this would render 21.0 unusable for me.

@kristofdho
Copy link
Author

I would like to restate the importance of this regression for us. Could I have some context on why this is not making 21.0, and what a possible workaround would be?

@pejovica
Copy link
Member

@kristofdho, I wouldn't necessarily call this a regression, because AWT is not yet supported on Windows (see #3084), but I also agree that this plugin should not be needed.

So until this is fixed, you can pass -Djava.awt.headless=false to native-image when building an image as a workaround, i.e.:

> native-image -H:Name=BakedInHeadlessPoc -H:Class=BakedInHeadlessPoc --verbose --no-fallback -Djava.awt.headless=false
...

> BakedInHeadlessPoc
false

> BakedInHeadlessPoc -Djava.awt.headless=true
false

> BakedInHeadlessPoc -Djava.awt.headless=false
false

@zakkak
Copy link
Collaborator

zakkak commented Feb 2, 2021

Can someone please add the platform-windows label to this issue?

@munishchouhan
Copy link
Contributor

@zakkak done

@zakkak
Copy link
Collaborator

zakkak commented Feb 3, 2021

Thank you @mcraj017 !

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

Successfully merging a pull request may close this issue.

6 participants