Skip to content

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

Closed

Description

@sdeleuze

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.

Activity

  1. oubidar-Abderrahim commented on Apr 8, 2022

    @oubidar-Abderrahim
    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

  2. LilPoppy commented on Apr 8, 2022

    @LilPoppy

    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

  3. sdeleuze commented on Apr 10, 2022

    @sdeleuze
    CollaboratorAuthor

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

  4. oubidar-Abderrahim commented on Apr 11, 2022

    @oubidar-Abderrahim
    Member

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

  5. sdeleuze commented on Apr 11, 2022

    @sdeleuze
    CollaboratorAuthor

    Sure:

  6. oubidar-Abderrahim commented on Apr 26, 2022

    @oubidar-Abderrahim
    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)

  7. michelu89 commented on May 3, 2022

    @michelu89

    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
    ```
    
  8. oubidar-Abderrahim commented on May 4, 2022

    @oubidar-Abderrahim
    Member

    Tracked internally on GR--38563

  9. christianwimmer commented on May 4, 2022

    @christianwimmer

    @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?

  10. 2 remaining items

  11. christianwimmer commented on Jun 10, 2022

    @christianwimmer

    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.

  12. sdeleuze commented on Dec 21, 2022

    @sdeleuze
    CollaboratorAuthor

    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?

  13. teshull commented on Dec 21, 2022

    @teshull
    Member

    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

  14. samuelAndalon commented on Apr 22, 2023

    @samuelAndalon

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

  15. sdeleuze commented on Apr 24, 2023

    @sdeleuze
    CollaboratorAuthor

    Any chance to fix that in next major release?

  16. christianwimmer commented on Apr 24, 2023

    @christianwimmer

    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.

  17. otcyury commented on May 23, 2023

    @otcyury

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

  18. oliveryasuna commented on Jun 21, 2023

    @oliveryasuna

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

  19. nsoubelet commented on Jan 27, 2024

    @nsoubelet

    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?

  20. teshull commented on Jan 27, 2024

    @teshull
    Member

    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

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions