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

[Java 21] Fix profiler test #43471

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.ballerina.runtime.api.types.Parameter;

import java.util.Optional;
import java.util.function.Supplier;

/**
* When this class is used as the first argument of an interop method, Ballerina will inject an instance of
Expand All @@ -47,9 +48,9 @@ public abstract class Environment {
/**
* Yield the current execution and run some operation so other non isolated functions can run in asynchronously.
*
* @param runnable operation to be executed.
* @param supplier operation to be executed.
*/
public abstract void yieldAndRun(Runnable runnable);
public abstract Object yieldAndRun(Supplier<Object> supplier);

/**
* Gets an instance of Ballerina runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.ballerina.runtime.internal.scheduling.Strand;

import java.util.Optional;
import java.util.function.Supplier;

/**
* When {@link Environment} is used as the first argument of an interop method, Ballerina will inject an instance
Expand Down Expand Up @@ -69,10 +70,10 @@ public Parameter[] getFunctionPathParameters() {
}

@Override
public void yieldAndRun(Runnable runnable) {
public Object yieldAndRun(Supplier<Object> supplier) {
try {
strand.yield();
runnable.run();
return supplier.get();
} finally {
strand.resume();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public BLockStore() {
*/
@SuppressWarnings("unused")
public void lock(Strand strand, String lockName) {
strand.yield();
getLockFromMap(lockName).lock();
strand.acquiredLockCount++;
strand.resume();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
public class AsyncUtils {

public static Object handleNonIsolatedStrand(Strand strand, Supplier<?> resultSupplier) {
// This check required for non strand Threads.
boolean runnable = strand.isRunnable();
if (runnable) {
strand.yield();

}
Object result = resultSupplier.get();
if (runnable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public static Strand getStrand() {
if (strand != null) {
return strand;
}
return daemonStrand;
if (daemonStrand == null) {
return null;
}
return new Strand(null, null, daemonStrand.scheduler, daemonStrand, false, null, null);
}
public Object call(Module module, String functionName, Strand parentStrand, Object... args) {
boolean runnable = parentStrand.isRunnable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public void resume() {
checkStrandCancelled();
if (!this.isIsolated && !scheduler.globalNonIsolatedLock.isHeldByCurrentThread()) {
this.scheduler.globalNonIsolatedLock.lock();

}
}

Expand All @@ -103,7 +102,7 @@ public void yield() {
}

public void done() {
if (!isIsolated && scheduler.globalNonIsolatedLock.isHeldByCurrentThread()) {
if (!this.isIsolated && scheduler.globalNonIsolatedLock.isHeldByCurrentThread()) {
scheduler.globalNonIsolatedLock.unlock();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void sleep(Environment env, BDecimal delaySeconds) {
env.yieldAndRun(() -> {
try {
Thread.sleep(delay);
return null;
} catch (InterruptedException e) {
throw ErrorCreator.createError(StringUtils.fromString("error occurred during sleep"), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ public void testProfilerExecutionWithKillSignal() throws BallerinaTestException
bMainInstance.waitForLeechers(List.of(beforeExecleechers), 20000);
addLogLeechers(afterExecleechers, serverInfoLogReader);
Thread.sleep(5000);
long processId = process.pid();
Runtime.getRuntime().exec("kill -SIGINT " + processId);
ProcessHandle profilerHandle = process.children().findFirst().get().children().findFirst().get();
long profileId = profilerHandle.pid();
long balProcessID = profilerHandle.children().findFirst().get().pid();
Runtime.getRuntime().exec("kill -SIGINT " + balProcessID);
Runtime.getRuntime().exec("kill -SIGINT " + profileId);
bMainInstance.waitForLeechers(List.of(afterExecleechers), 20000);
process.waitFor();
} catch (InterruptedException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static void sleep(Environment env, long delayMillis) {
env.yieldAndRun(() -> {
try {
Thread.sleep(delayMillis);
return null;
} catch (InterruptedException e) {
throw ErrorCreator.createError(e);
}
Expand Down
Loading