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

ArrayIndexOutOfBoundsException with -Dco.paralleluniverse.fibers.verifyInstrumentation=true #1

Open
ctemple opened this issue Sep 26, 2022 · 0 comments

Comments

@ctemple
Copy link

ctemple commented Sep 26, 2022

OpenJDK 11.0.13

package org.example;

import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.fibers.Suspendable;
import co.paralleluniverse.strands.SuspendableRunnable;
import co.paralleluniverse.strands.channels.Channels;
import co.paralleluniverse.strands.channels.IntChannel;
import co.paralleluniverse.strands.concurrent.Semaphore;

import java.io.IOException;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class QuasarTest {
	static ThreadLocal<Integer> s_local = new ThreadLocal<>();

	@Suspendable
	static boolean fn1(Semaphore ss) {
		try {
			return ss.tryAcquire(2, 100, TimeUnit.MILLISECONDS);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
	}

	@Suspendable
	static void fn2(Semaphore ss, Integer integer, int i) {
		try {
			System.out.println(String.format("get %s i=%d local=%d thread=%s t=%d", integer, i,
					s_local.get(),
					Thread.currentThread().getName(), System.nanoTime()));
			Fiber.park(1, TimeUnit.MILLISECONDS);
			System.out.println("done " + System.nanoTime());

			fn1(ss);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	static void doAll2() {
		for (int k = 0; k < 2; ++k) {
			final int saveLocal = k;
			final IntChannel increasingToEcho = Channels.newIntChannel(10);
			final Semaphore ss = new Semaphore(1);
			new Fiber<Void>(new SuspendableRunnable() {
				@Override
				public void run() throws SuspendExecution, InterruptedException {
					s_local.set(saveLocal);
					for (int i = 0; i < 100000; ++i) {
						Integer integer = increasingToEcho.receive();
						if (integer != null && integer != 0) {
							fn2(ss, integer, i);
						} else {
							System.out.println("空的");
						}
					}
				}
			}).start();

			try {
				increasingToEcho.send(11);
			} catch (SuspendExecution e) {
				throw new RuntimeException(e);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}

			new Fiber<Void>(new SuspendableRunnable() {
				@Override
				public void run() throws SuspendExecution, InterruptedException {
					Random random = new Random();
					while (true) {
						int t = random.nextInt(10) + 1;
						increasingToEcho.send(t);
						ss.release();
						Fiber.sleep(200 * t);
					}
				}
			}).start();
		}

		while (true) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
		}
	}

	static public void main(String[] args) throws ExecutionException, InterruptedException, SuspendExecution, IOException {
		doAll2();
	}
}

output

D:\tools\jdk-11.0.13\bin\java.exe -Dco.paralleluniverse.fibers.verifyInstrumentation=true -javaagent:C:\Users\caobi.m2\repository\com\hiddenswitch\quasar-core\10.0.6\quasar-core-10.0.6.jar -javaagent:D:\tools\JetBrains\Toolbox\apps\IDEA-U\ch-0\222.4167.29\lib\idea_rt.jar=64693:D:\tools\JetBrains\Toolbox\apps\IDEA-U\ch-0\222.4167.29\bin -Dfile.encoding=UTF-8 -classpath D:\workspace_test\test_quasar\target\classes;C:\Users\caobi.m2\repository\com\hiddenswitch\quasar-core\10.0.6\quasar-core-10.0.6.jar org.example.QuasarTest
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on co.paralleluniverse.concurrent.util.ThreadAccess (file:/C:/Users/caobi/.m2/repository/com/hiddenswitch/quasar-core/10.0.6/quasar-core-10.0.6.jar) to class java.lang.Thread
WARNING: Please consider reporting this to the maintainers of co.paralleluniverse.concurrent.util.ThreadAccess
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
get 11 i=0 local=1 thread=ForkJoinPool-default-fiber-pool-worker-23 t=6588721005141800
get 11 i=0 local=0 thread=ForkJoinPool-default-fiber-pool-worker-19 t=6588721002528600
Exception in Fiber "fiber-10000002" Exception in Fiber "fiber-10000004" Exception in Fiber "fiber-10000003" Exception in Fiber "fiber-10000001" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.getStackTraceElement0(ExtendedStackTraceHotSpot.java:164)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.access$300(ExtendedStackTraceHotSpot.java:33)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.getStackTraceElement0(ExtendedStackTraceHotSpot.java:164)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.getStackTraceElement0(ExtendedStackTraceHotSpot.java:164)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.access$300(ExtendedStackTraceHotSpot.java:33)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:64)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:46)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.getStackTraceElement0(ExtendedStackTraceHotSpot.java:164)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.get(ExtendedStackTraceHotSpot.java:80)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.access$300(ExtendedStackTraceHotSpot.java:33)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:64)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:64)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1706)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.access$300(ExtendedStackTraceHotSpot.java:33)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1690)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1686)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1659)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1654)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:46)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:46)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.get(ExtendedStackTraceHotSpot.java:80)
at co.paralleluniverse.fibers.Fiber.park(Fiber.java:633)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:64)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot$1.next(ExtendedStackTraceHotSpot.java:46)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.get(ExtendedStackTraceHotSpot.java:80)
at co.paralleluniverse.fibers.Fiber.park(Fiber.java:649)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1706)
at co.paralleluniverse.common.util.ExtendedStackTraceHotSpot.get(ExtendedStackTraceHotSpot.java:80)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1690)
at org.example.QuasarTest.fn2(QuasarTest.java:36)
at org.example.QuasarTest$1.run(QuasarTest.java:57)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:42)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:30)
at co.paralleluniverse.fibers.Fiber.run(Fiber.java:1089)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1706)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1686)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1706)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1659)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1690)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1654)
at co.paralleluniverse.fibers.Fiber.park(Fiber.java:633)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1690)
at co.paralleluniverse.fibers.Fiber.park(Fiber.java:649)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1686)
at org.example.QuasarTest.fn2(QuasarTest.java:36)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation(Fiber.java:1686)
at org.example.QuasarTest$1.run(QuasarTest.java:57)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1659)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:42)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1659)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:30)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1654)
at co.paralleluniverse.fibers.Fiber.sleep(Fiber.java:685)
at co.paralleluniverse.fibers.Fiber.sleep(Fiber.java:677)
at org.example.QuasarTest$2.run(QuasarTest.java:81)
at co.paralleluniverse.fibers.Fiber.run(Fiber.java:1089)
at co.paralleluniverse.fibers.Fiber.verifySuspend(Fiber.java:1654)
at co.paralleluniverse.fibers.Fiber.sleep(Fiber.java:685)
at co.paralleluniverse.fibers.Fiber.sleep(Fiber.java:677)
at org.example.QuasarTest$2.run(QuasarTest.java:81)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:42)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:42)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:30)
at co.paralleluniverse.fibers.Fiber.run(Fiber.java:1089)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run(SuspendableUtils.java:30)
at co.paralleluniverse.fibers.Fiber.run(Fiber.java:1089)

Process finished with exit code 130

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

No branches or pull requests

1 participant