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

Update Graal to v22.x #2009

Closed
edwardsph opened this issue May 10, 2022 · 34 comments
Closed

Update Graal to v22.x #2009

edwardsph opened this issue May 10, 2022 · 34 comments
Assignees

Comments

@edwardsph
Copy link
Contributor

I use Quarkus 2.7.5.Final with Karate 1.2.0. I can't move to later versions of Quarkus as they rely on Graal v22 and Karate only works with v21. I'm aware there are some issues with moving to v22 as I've seen the tests fail myself but unfortunately, I don't have the knowledge or experience to help. Just creating this issue in the hope you can put it on the roadmap now that 1.2.0 is released. Thanks.

@ptrthomas ptrthomas self-assigned this May 10, 2022
@ptrthomas ptrthomas added this to the 1.3.0 milestone May 10, 2022
ptrthomas added a commit that referenced this issue Jun 2, 2022
@ptrthomas
Copy link
Member

@edwardsph upgraded and a couple of things broke, which don't look too bad, but please check with your suites when you get a chance. 2 tests have been commented out

@joelpramos I think the solution is related to the changes you made in #1828 and I know that code and PR merge was done in a rush. I hope I get time to do a massive cleanup and use the Graal "child context" concept refer: https://github.com/oracle/graal/blob/master/docs/reference-manual/embedding/embed-languages.md#embed-guest-languages-in-guest-languages and discussion

@ptrthomas
Copy link
Member

CI failed:

Error:  Failures: 
Error:    PaymentServiceContractTest.testPaymentService:33 Multi threaded access requested by thread Thread[main,5,main] but is not allowed for language(s) js.
classpath:mock/contract/payment-service.feature:17

@ptrthomas
Copy link
Member

just realized Graal 22.1 requires Java 11 ! https://github.com/oracle/graaljs/blob/master/CHANGELOG.md#version-2210

glad the build is set up to detect these problems:

Error:  COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
Error:  /karate/karate-e2e-tests/src/test/java/driver/JavaApiRunner.java:[33,60] cannot access org.graalvm.polyglot.proxy.ProxyObject
  bad class file: /root/.m2/repository/org/graalvm/sdk/graal-sdk/22.1.0.1/graal-sdk-22.1.0.1.jar(org/graalvm/polyglot/proxy/ProxyObject.class)
    class file has wrong version 55.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
[INFO] 1 error

what does everyone think - is it time to move to Java 11 ? cc @packleader

ptrthomas added a commit that referenced this issue Jun 2, 2022
@joelpramos
Copy link
Contributor

if I recall correctly there's some properties in the Config that can be function (e.g. afterFeature etc.) and I think that's why that PR was needed when sharing context (probably sharing between background scenario and each scenario of a Dynamic Scenario Outline in which background is executed independently and then shared with each execution of the scenarios).

In theory the last time I followed some of your links of latest on Graal all of this rehydration code should go away anyways but that'll probably be quite a risky refactor without lots of people testing it

@ptrthomas
Copy link
Member

@edwardsph I think you will be able to use the latest version of graal without any issues by adding these to your pom.xml and over-ride. Karate never shades these JARs anyway and the latest version allows you to over-ride any JAR, even the ones shaded in the "fatjar". do confirm !

        <!--
        <graal.version>22.1.0.1</graal.version>
        -->

        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>${graal.version}</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js</artifactId>
            <version>${graal.version}</version>
            <scope>runtime</scope>
        </dependency>

@packleader
Copy link
Contributor

I'm in favor of going all-in with Java 11. Lot's of other mainstream projects are dropping support for Java 8 (eg. Sonarqube, GraalVM), so we'd be in good company. And if we try to keep support for Java 8, we would likely miss out on newer versions of such libraries. Karate 1.2.0 was a solid release, so devs that don't want to move to Java 8 will still be able to benefit from Karate.

We might want to think about how we deal with any critical bugs that get reported against Karate 1.2.0. If we only apply the fixes to develop for 1.3.0, then our users won't have access to those fixes unless they move to Java 11. We may need a model where we branch from the 1.2.0 tag and apply the fixes for any critical bugs. That way we can publish 1.2.1, etc. with the bugfixes available to teams that are still on Java 8.

@ptrthomas
Copy link
Member

@packleader thanks ! I agree with your assessment, and 1.2.0 is a pretty solid release. I think creating a branch for 1.2.0 is the way to go. for now, I intend to re-write some of the code in ScenarioEngine on develop itself, just hope I get time this month

@ptrthomas
Copy link
Member

all: 1.2.1.RC2 should be in maven central now using graal-js 22.0

@edwardsph
Copy link
Contributor Author

It hasn't arrived there yet but I look forward to testing it out when it does. I was already using the direct dependencies in the pom as you suggest above but still had issues with that. Hopefully the other changes you have made will resolve those. Thanks.

@edwardsph
Copy link
Contributor Author

Good news - this is all working for me:

        <quarkus.version>2.9.2.Final</quarkus.version>
        <karate.version>1.2.1.RC2</karate.version>
        <graal.version>22.0.0.2</graal.version>

I tried this with Graal 22.1.0.1 but the process just locks up but this could be an issue with Quarkus. For now, this is a really helpful step forwards as the latest Karate and Quarkus rely on 22.0.0.2.

@ptrthomas
Copy link
Member

@edwardsph thanks for the update !

@mattkoss
Copy link

Yes indeed, it locks up with graal 22.1.x., same goes with 22.2.0, so cannot manually override in the pom.xml.

I ran into some weird memory leak issue, and after a bit of googling ran into this:
oracle/graaljs#607

Any chance of getting karate upgraded to graal 22.1.x or higher? (22.2.0 is out already....)

@ptrthomas
Copy link
Member

@mattkoss contributions welcome ;)

ptrthomas added a commit that referenced this issue Jul 31, 2022
@ptrthomas
Copy link
Member

tagging #1883 as a related issue for future reference

ptrthomas added a commit that referenced this issue Jul 31, 2022
still an issue with parallel scenario, but no longer the multi-thread issue
guess is that variables are being over-written by another scenario-thread
websocket may not be possible to do with custom js functions
so we will limit or revise existiing documented approach
ptrthomas added a commit that referenced this issue Aug 2, 2022
feels good to get rid of that horrible recurse and attach stuff
ptrthomas added a commit that referenced this issue Aug 2, 2022
in small steps because of how much trouble this caused in the past
ptrthomas added a commit that referenced this issue Aug 2, 2022
@joelpramos
Copy link
Contributor

What are the context sharing changes? I think (without much digging) that variables defined in karate-config.js are not accessible but someone in karate-base.js are.

@ptrthomas
Copy link
Member

there are no context sharing changes.

@joelpramos
Copy link
Contributor

joelpramos commented Aug 26, 2022

There's a change in behavior which I think goes back to a previous Graal/Nashorn behavior (before we started fixing all context switching). E.g. below:

karate-config.js

function fn() {
  var config = {};
  config.utils = karate.call('classpath:com/intuit/karate/core/jscall/utils.feature');
  return config;
}

utils.feature

Feature:

Scenario:
* def sayHello = function() { return 'hello world!' }
* def useExistingFunction =
  """
  function() {
    return sayHello();
  }
  """

Before the latest changes to Graal 22.0 we'd call the other function by using utils.sayHello() and now we should call it by using sayHello(), otherwise we get an error like 'utils reference not found' or similar. I am fairly certain this is just going back to how Nashorn used to work and I do prefer it.

Don't think it's a problem but rather something that should be part of release notes as a breaking change.

joelpramos added a commit to joelpramos/karate that referenced this issue Aug 26, 2022
@ptrthomas
Copy link
Member

not sure it is a breaking change, but it is "better" support for JS. anyway this is what RC releases are for. thanks !

ptrthomas added a commit that referenced this issue Aug 26, 2022
@joelpramos
Copy link
Contributor

No other reports of impacts with 1.2.1.RC2 @ptrthomas

@mattkoss
Copy link

mattkoss commented Sep 8, 2022

After upgrading to 1.3.0.RC2 - I see this still uses Graal 22.0.x so the memory leak is still there.
I tried to see if I can resolve issues after override to 22.1.x - but this seems quite tricky for someone with my skills :)

Am I right in thinking that this upgrade is a major job, @ptrthomas?

@ptrthomas
Copy link
Member

it may not be, but I hope you can wait approx 6 weeks. this is the issue you can watch: #2083

@ptrthomas
Copy link
Member

but @mattkoss if you see comment from @edwardsph - I think you can use Java 11 and force a new version of Graal and things may just work. here is a pom where I was able to do this: https://github.com/ptrthomas/karate-oas-demo/blob/ac08c940888c9eca652eed3725320eff0352ad21/pom.xml

@mattkoss
Copy link

mattkoss commented Sep 9, 2022

Tried this, but still getting:

<<<
[ERROR] execute  Time elapsed: 1.334 s  <<< ERROR!
org.graalvm.polyglot.PolyglotException: java.lang.NoClassDefFoundError: com.oracle.truffle.js.lang.JavaScriptLanguage (initialization failure)

@edwardsph
Copy link
Contributor Author

In case it helps, my project uses Graal 22.1.0 with Karate 1.3.0.RC2: https://github.com/solid-contrib/conformance-test-harness/blob/main/pom.xml

@mattkoss
Copy link

mattkoss commented Sep 9, 2022

Unfortunately still getting the above exception, I wonder how this works for you, @edwardsph.
JavaScriptLanguage is there in the graal js jar, but it fails to be initialised, getting errors like:

org.graalvm.polyglot.PolyglotException: java.lang.NoClassDefFoundError: com.oracle.truffle.js.lang.JavaScriptLanguage (initialization failure)

	at java.base/java.lang.J9VMInternals.initializationAlreadyFailed(J9VMInternals.java:136)
	at com.oracle.truffle.js.lang.JavaScriptLanguageProvider.create(JavaScriptLanguageProvider.java:51)
	at com.oracle.truffle.polyglot.LanguageCache.loadLanguage(LanguageCache.java:548)
	at com.oracle.truffle.polyglot.PolyglotLanguageInstance.<init>(PolyglotLanguageInstance.java:100)
	at com.oracle.truffle.polyglot.PolyglotLanguage.getInitLanguage(PolyglotLanguage.java:152)
	at com.oracle.truffle.polyglot.PolyglotLanguage.ensureInitialized(PolyglotLanguage.java:142)
	at com.oracle.truffle.polyglot.PolyglotLanguage.getOptionsInternal(PolyglotLanguage.java:134)
	at com.oracle.truffle.polyglot.PolyglotLanguage.getOptionValues(PolyglotLanguage.java:202)
	at com.oracle.truffle.polyglot.PolyglotContextConfig.<init>(PolyglotContextConfig.java:266)
	at com.oracle.truffle.polyglot.PolyglotEngineImpl.createContext(PolyglotEngineImpl.java:1745)
	at com.oracle.truffle.polyglot.PolyglotEngineDispatch.createContext(PolyglotEngineDispatch.java:159)
	at org.graalvm.polyglot.Context$Builder.build(Context.java:1832)
	at com.intuit.karate.graal.JsEngine.createContext(JsEngine.java:79)
	at com.intuit.karate.graal.JsEngine.access$000(JsEngine.java:47)
	at com.intuit.karate.graal.JsEngine$1.initialValue(JsEngine.java:63)
	at com.intuit.karate.graal.JsEngine$1.initialValue(JsEngine.java:60)
	at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
	at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
	at com.intuit.karate.graal.JsEngine.local(JsEngine.java:99)
	at com.intuit.karate.report.Report$Builder.build(Report.java:122)
	at com.intuit.karate.report.SuiteReports.timelineReport(SuiteReports.java:62)
	at com.intuit.karate.Results.<init>(Results.java:97)
	at com.intuit.karate.Results.of(Results.java:57)
	at com.intuit.karate.Suite.buildResults(Suite.java:373)
	at com.intuit.karate.Runner$Builder.parallel(Runner.java:501)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$144/0000000000000000.apply(Unknown Source)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall$$Lambda$145/0000000000000000.apply(Unknown Source)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$$Lambda$356/0000000000000000.apply(Unknown Source)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:210)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor$$Lambda$642/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:206)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:131)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:65)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$219/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$218/0000000000000000.invoke(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$217/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService$$Lambda$223/0000000000000000.accept(Unknown Source)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$219/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$218/0000000000000000.invoke(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$217/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService$$Lambda$223/0000000000000000.accept(Unknown Source)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$219/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$218/0000000000000000.invoke(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask$$Lambda$217/0000000000000000.execute(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator$$Lambda$174/0000000000000000.accept(Unknown Source)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.RuntimeException: failed to get hash field offset
	at com.oracle.truffle.api.strings.TStringUnsafe.getStringDeclaredField(TStringUnsafe.java:90)
	at com.oracle.truffle.api.strings.TStringUnsafe.<clinit>(TStringUnsafe.java:79)
	at com.oracle.truffle.api.strings.TStringInternalNodes$FromJavaStringUTF16Node.doNonEmpty(TStringInternalNodes.java:1394)
	at com.oracle.truffle.api.strings.TStringInternalNodesFactory$FromJavaStringUTF16NodeGen$Uncached.execute(TStringInternalNodesFactory.java:3919)
	at com.oracle.truffle.api.strings.TruffleString$FromJavaStringNode.doUTF16(TruffleString.java:1922)
	at com.oracle.truffle.api.strings.TruffleStringFactory$FromJavaStringNodeGen$Uncached.execute(TruffleStringFactory.java:723)
	at com.oracle.truffle.api.strings.TruffleString$FromJavaStringNode.execute(TruffleString.java:1900)
	at com.oracle.truffle.api.strings.TruffleString.fromJavaStringUncached(TruffleString.java:1955)
	at com.oracle.js.parser.ParserStrings.constant(ParserStrings.java:52)
	at com.oracle.js.parser.ParserStrings.<clinit>(ParserStrings.java:49)
	at com.oracle.truffle.js.runtime.JSRealm.<clinit>(JSRealm.java:211)
	at com.oracle.truffle.js.runtime.JSContextOptions.<clinit>(JSContextOptions.java:457)
	at com.oracle.truffle.js.lang.JavaScriptLanguage.<clinit>(JavaScriptLanguage.java:182)
	at com.oracle.truffle.js.lang.JavaScriptLanguageProvider.create(JavaScriptLanguageProvider.java:51)
	at com.oracle.truffle.polyglot.LanguageCache.loadLanguage(LanguageCache.java:548)
	at com.oracle.truffle.polyglot.PolyglotLanguageInstance.<init>(PolyglotLanguageInstance.java:100)
	at com.oracle.truffle.polyglot.PolyglotLanguage.getInitLanguage(PolyglotLanguage.java:152)
	at com.oracle.truffle.polyglot.PolyglotLanguage.ensureInitialized(PolyglotLanguage.java:142)
	at com.oracle.truffle.polyglot.PolyglotLanguage.getOptionsInternal(PolyglotLanguage.java:134)
	at com.oracle.truffle.polyglot.PolyglotLanguage.getOptionValues(PolyglotLanguage.java:202)
	at com.oracle.truffle.polyglot.PolyglotContextConfig.<init>(PolyglotContextConfig.java:266)
	at com.oracle.truffle.polyglot.PolyglotEngineImpl.createContext(PolyglotEngineImpl.java:1745)
	at com.oracle.truffle.polyglot.PolyglotEngineDispatch.createContext(PolyglotEngineDispatch.java:159)
	at org.graalvm.polyglot.Context$Builder.build(Context.java:1832)
	at com.intuit.karate.graal.JsEngine.createContext(JsEngine.java:79)
	at com.intuit.karate.graal.JsEngine.access$000(JsEngine.java:47)
	at com.intuit.karate.graal.JsEngine$1.initialValue(JsEngine.java:63)
	at com.intuit.karate.graal.JsEngine$1.initialValue(JsEngine.java:60)
	at java.base/java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:195)
	at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:172)
	at com.intuit.karate.graal.JsEngine.local(JsEngine.java:99)
	at com.intuit.karate.core.ScenarioEngine.init(ScenarioEngine.java:1042)
	at com.intuit.karate.core.ScenarioIterator.tryAdvance(ScenarioIterator.java:99)
	at com.intuit.karate.core.ScenarioIterator.tryAdvance(ScenarioIterator.java:88)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.lambda$initPartialTraversalState$0(StreamSpliterators.java:294)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator$$Lambda$287/0000000000000000.getAsBoolean(Unknown Source)
	at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.fillBuffer(StreamSpliterators.java:206)
	at java.base/java.util.stream.StreamSpliterators$AbstractWrappingSpliterator.doAdvance(StreamSpliterators.java:161)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.tryAdvance(StreamSpliterators.java:300)
	at java.base/java.util.Spliterators$1Adapter.hasNext(Spliterators.java:681)
	at com.intuit.karate.core.ParallelProcessor.execute(ParallelProcessor.java:69)
	at com.intuit.karate.core.FeatureRuntime.run(FeatureRuntime.java:170)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:836)
Caused by: java.lang.NoSuchFieldException: hash
	at java.base/java.lang.Class.getDeclaredFieldImpl(Native Method)
	at java.base/java.lang.Class.getDeclaredField(Class.java:898)
	at com.oracle.truffle.api.strings.TStringUnsafe.getStringDeclaredField(TStringUnsafe.java:88)
	... 47 more
Caused by: Attached Guest Language Frames (0)
Internal GraalVM error, please report at https://github.com/oracle/graal/issues/.

@mattkoss
Copy link

Funny enough, after refactoring to support 1.3.0.RC2, also memory usage has improved, but it still falls over after about 6000 tests.
Will wait for the graal upgrade and revisit.

@ptrthomas
Copy link
Member

@mattkoss sure. do consider creating a way to replicate the problem you are referring to, perhaps this thread will give you some pointers: #1685 - and there's some code you may be able to use as a base: https://github.com/karatelabs/karate/tree/master/examples/profiling-test

@joelpramos
Copy link
Contributor

There's a change in behavior which I think goes back to a previous Graal/Nashorn behavior (before we started fixing all context switching). E.g. below:

karate-config.js

function fn() {
  var config = {};
  config.utils = karate.call('classpath:com/intuit/karate/core/jscall/utils.feature');
  return config;
}

utils.feature

Feature:

Scenario:
* def sayHello = function() { return 'hello world!' }
* def useExistingFunction =
  """
  function() {
    return sayHello();
  }
  """

Before the latest changes to Graal 22.0 we'd call the other function by using utils.sayHello() and now we should call it by using sayHello(), otherwise we get an error like 'utils reference not found' or similar. I am fairly certain this is just going back to how Nashorn used to work and I do prefer it.

Don't think it's a problem but rather something that should be part of release notes as a breaking change.

@ptrthomas another variation of this that is a breaking change .. if you have help JS functions that access driver methods, the driver doesn't appear to be available anymore in that JS context. Didn't caught this earlier. Do you have any suggestions that don't involve passing the driver variable on all these functions?

joelpramos added a commit to joelpramos/karate that referenced this issue Oct 29, 2022
@joelpramos
Copy link
Contributor

@ptrthomas another variation of this that is a breaking change .. if you have help JS functions that access driver methods, the driver doesn't appear to be available anymore in that JS context. Didn't caught this earlier. Do you have any suggestions that don't involve passing the driver variable on all these functions?

This PR reproduces the issue to review/discuss #2160 . The additional logging was something I was planning on opening to get some extra details for another issue, unrelated with the actual issue but thought I'd include it too.

@ptrthomas
Copy link
Member

@joelpramos updated release notes: https://github.com/karatelabs/karate/wiki/1.3.0-Upgrade-Guide

for the driver I can only think of var driver = karate.get('driver') as mentioned here: https://stackoverflow.com/a/74237960/143475

open to any suggestions or PR-fixes

@ptrthomas
Copy link
Member

@joelpramos the driver not being available has always been like that, it depends on if you declare the function before or after the driver has been inited. there may be a smarter way to do this by making the driver object a smart proxy that can look up the one on the scenario-engine thread-local ... maybe

@joelpramos
Copy link
Contributor

That worked. Updated PR. I was looking into the ScenarioEngine.autoDef()) function and there's probably a smart way to use the same approach you use in the Karate DSL to automatically replace prior to creating the function with that karate.get('driver') and avoiding scenario-engine thread etc. Bit too much energy for now for me but I'm sure it should work.

I suggest adding as a minor variation in the notes as well. Noticed it's useful in teams with scripts handling SPAs.

ptrthomas pushed a commit that referenced this issue Oct 31, 2022
* adding extra logging

* adding access to skipBackground variable

* reproduce #2009 (comment)

* applying suggested approach to unit test

* update after sync with latest from develop

* PR comments
@ptrthomas
Copy link
Member

1.3.0 released

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

No branches or pull requests

5 participants