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

--language:js seems to disable inlining in native images #4473

Closed
sdeleuze opened this issue Apr 5, 2022 · 21 comments
Closed

--language:js seems to disable inlining in native images #4473

sdeleuze opened this issue Apr 5, 2022 · 21 comments
Assignees
Labels
bug native-image spring spring related issue

Comments

@sdeleuze
Copy link
Collaborator

sdeleuze commented Apr 5, 2022

Based on what we discussed in this Spring Native issue, using --language:js seems to disable inlining like if -H:-InlineBeforeAnalysis was applied, breaking Spring Boot applications compiled with Spring Native.

Please tag this issue with the spring label.

@oubidar-Abderrahim
Copy link
Member

Thank you for reporting this, we will take a look and get back to you, in the meantime could you share the steps to reproduce the issue

@LilPoppy
Copy link

LilPoppy commented Apr 8, 2022

Thank you for reporting this, we will take a look and get back to you, in the meantime could you share the steps to reproduce the issue

Hi @oubidar-Abderrahim

Pull newest from repository first:
git clone https://github.com/StorebeansDev/cobnet.git

Check if you have any Redis port opening:
sudo lsof -i :6379

Kill the redis if you have any exists:
kill -9 [pid]

Then run the following:
mvn -Dredis-host=redis -Ddb-host=db clean install -Pdocker -Ddocker-target=native

After done container run:
docker start -a cobnet

@sdeleuze
Copy link
Collaborator Author

Can be reproduced without that with just a simple Spring webapp.

@oubidar-Abderrahim
Copy link
Member

Thank you @sdeleuze, could you please share the simple Spring webapp for clarity?

@sdeleuze
Copy link
Collaborator Author

Sure:

@oubidar-Abderrahim
Copy link
Member

Hi @sdeleuze ,
I couldn't reproduce the issue using the steps you provided, here is what I did:

  1. set GraalVM EE java11 22.1.0 as default java
  2. Cloned https://github.com/spring-projects-experimental/spring-native
  3. cd samples/webflux-netty
  4. added @NativeHint(options = "--language:js") to WebfluxApplication like this:
package com.example.webflux;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.nativex.hint.NativeHint;

@NativeHint(options = "--language:js")
@SpringBootApplication
public class WebfluxApplication {

	public static void main(String[] args) {
		SpringApplication.run(WebfluxApplication.class, args);
	}

	@RestController
	class Foo {

		@GetMapping("/")
		public String greet() {
			return "hi!";
		}
	}
}
  1. ./build.sh

the output I get:

=== Building webflux-netty sample ===
Packaging webflux-netty with Maven (native)
SUCCESS
Testing webflux-netty
SUCCESS
Build memory: 7.77GB
Image build time: 2m 40s
RSS memory: 82.3M
Image size: 123.8M
Startup time: 0.176 (JVM running for 0.178)
Lines of reflective config: 2361

Am I missing something? what version of GraalVM did you reproduce with? jdk11 or 17? CE or EE? which OS? (I tested on Linux amd64 Ubuntu 18.04)

@michelu89
Copy link

michelu89 commented May 3, 2022

Hi @oubidar-Abderrahim,

The problem when testing my Spring application comes to a similar problem as @sdeleuze mentioned.

What are my steps:

  1. MacOs Monterey
  2. set GraalVM EE java11 22.1.0 as default java
  3. Cloned https://github.com/spring-projects-experimental/spring-native
  4. cd samples/webmvc-tomcat (Important, since Netty works for me too)
  5. added @NativeHint(options = "--language:js") to WebmvcApplication like this:
package com.example.webmvc;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.nativex.hint.NativeHint;

@NativeHint( options = "--language:js" )
@SpringBootApplication
public class WebmvcApplication {

   public static void main( final String[] args ) {
      SpringApplication.run( WebmvcApplication.class, args );
   }
}

  1. ./build.sh

starting the executable it get this output:

2022-05-03 12:48:07.268  INFO 4910 --- [           main] o.s.nativex.NativeListener               : AOT mode enabled

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.6)

2022-05-03 12:48:07.270  INFO 4910 --- [           main] com.example.webmvc.WebmvcApplication     : Starting WebmvcApplication v0.0.1-SNAPSHOT using Java 11.0.14 on FE-C-005QM with PID 4910 (/Users/user/Downloads/spring-native-main/samples/webmvc-tomcat/target/webmvc-tomcat started by user in /Users/user/Downloads/spring-native-main/samples/webmvc-tomcat/target)
2022-05-03 12:48:07.270  INFO 4910 --- [           main] com.example.webmvc.WebmvcApplication     : No active profile set, falling back to 1 default profile: "default"
2022-05-03 12:48:07.284  INFO 4910 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-05-03 12:48:07.285  INFO 4910 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-05-03 12:48:07.285  INFO 4910 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.60]
2022-05-03 12:48:07.293  INFO 4910 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-05-03 12:48:07.293  INFO 4910 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 22 ms
2022-05-03 12:48:07.303  WARN 4910 --- [           main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping': Unexpected exception during bean creation; nested exception is java.lang.ExceptionInInitializerError
2022-05-03 12:48:07.303  INFO 4910 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-05-03 12:48:07.304 ERROR 4910 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping': Unexpected exception during bean creation; nested exception is java.lang.ExceptionInInitializerError
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:555) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[na:na]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[na:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[webmvc-tomcat:2.6.6]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[webmvc-tomcat:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[webmvc-tomcat:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[webmvc-tomcat:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[webmvc-tomcat:2.6.6]
        at com.example.webmvc.WebmvcApplication.main(WebmvcApplication.java:12) ~[webmvc-tomcat:0.0.1-SNAPSHOT]
Caused by: java.lang.ExceptionInInitializerError: null
        at java.lang.Class.ensureInitialized(DynamicHub.java:510) ~[webmvc-tomcat:na]
        at java.lang.Class.ensureInitialized(DynamicHub.java:510) ~[webmvc-tomcat:na]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.createRequestMappingHandlerMapping(WebMvcConfigurationSupport.java:351) ~[webmvc-tomcat:5.3.18]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.createRequestMappingHandlerMapping(WebMvcAutoConfiguration.java:543) ~[webmvc-tomcat:2.6.6]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping(WebMvcConfigurationSupport.java:311) ~[webmvc-tomcat:5.3.18]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.requestMappingHandlerMapping(WebMvcAutoConfiguration.java:445) ~[webmvc-tomcat:2.6.6]
        at org.springframework.aot.ContextBootstrapInitializer.lambda$initialize$23(ContextBootstrapInitializer.java:174) ~[na:na]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar$ThrowableFunction.apply(BeanDefinitionRegistrar.java:294) ~[na:na]
        at org.springframework.aot.beans.factory.InjectedElementResolver.create(InjectedElementResolver.java:67) ~[na:na]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar$BeanInstanceContext.create(BeanDefinitionRegistrar.java:211) ~[na:na]
        at org.springframework.aot.ContextBootstrapInitializer.lambda$initialize$24(ContextBootstrapInitializer.java:174) ~[na:na]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar$ThrowableFunction.apply(BeanDefinitionRegistrar.java:294) ~[na:na]
        at org.springframework.aot.beans.factory.BeanDefinitionRegistrar.lambda$instanceSupplier$0(BeanDefinitionRegistrar.java:115) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[na:na]
        ... 14 common frames omitted
Caused by: java.lang.IllegalStateException: Expected method not found: java.lang.NoSuchMethodException: org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$EmptyHandler.handle()
        at org.springframework.util.ClassUtils.getMethod(ClassUtils.java:1141) ~[na:na]
        at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.<clinit>(AbstractHandlerMethodMapping.java:84) ~[na:na]
        ... 31 common frames omitted
```

@oubidar-Abderrahim
Copy link
Member

Tracked internally on GR--38563

@christianwimmer
Copy link
Member

@sdeleuze Yes, currently method inlining before analysis is not supported when a Truffle language is in the image. This requires a pretty big rewrite of how we compile the deoptimization entry points. We know how to do it, but just did not have the time yet to get it implemented.

So the main question is: how important is that for you? Do you have use cases where you want to integrate JavaScript into Spring applications?

@michelu89
Copy link

@christianwimmer There is a Java library GraphViz that creates diagrams using a Javascript engine and this could live in a Spring project.

There could be several use-cases to generate a graph in your application. Imagine all the applications that want to have a pie chart from tables or similar things.

@sdeleuze
Copy link
Collaborator Author

sdeleuze commented Jun 10, 2022

@christianwimmer I guess there are some use cases like the one mentioned by @michelu89, but i am not sure how frequent they are. Concretely, the impact is that Spring Boot 3 will document that --language:js is not supported due to this issue.

@christianwimmer
Copy link
Member

I have this issue on the list to be addressed over the next months, I hope we get it done for the 22.3 release in fall.

@sdeleuze
Copy link
Collaborator Author

This issue is still pending and prevents any Spring Boot 3 application to enable the language support, see https://github.com/eregon/truffleruby-embed-spring. Any chance you could remove this limitation?

@teshull
Copy link
Member

teshull commented Dec 21, 2022

We are actively working on removing this limitation, but it requires many changes. I'll post an update here when InlineBeforeAnalysis is compatible with Truffle languages

@samuelAndalon
Copy link

just faced the same problem, currently trying the js support in a native image with Spring Boot 3

@sdeleuze
Copy link
Collaborator Author

Any chance to fix that in next major release?

@christianwimmer
Copy link
Member

We have been working on the necessary changes for a while, so there is a good chance it will be ready for GraalVM 23.1 in fall. But until everything is working, we cannot guarantee it.

@otcyury
Copy link

otcyury commented May 23, 2023

Will --language:js use with native build work with latest Quarkus based apps?

@oliveryasuna
Copy link

Facing this problem with --language:python in GraalVM 22.3.r17-grl.

@nsoubelet
Copy link

Hello @christianwimmer, based on the lack of activity for almost a year, I understand that this was not fixed yet nor you're planning to include a fix soon.
Is that correct?

@teshull
Copy link
Member

teshull commented Jan 27, 2024

Hi, with the release of 23.1, InlineBeforeAnalysis is compatible with Truffle languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug native-image spring spring related issue
Projects
None yet
Development

No branches or pull requests

10 participants