MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / DeepRecursion

Class DeepRecursion

test/test/depth/DeepRecursion.java:10–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.util.concurrent.ThreadLocalRandom;
9
10public class DeepRecursion {
11 private static int BASE_DEPTH;
12 private static int VAR_DEPTH;
13
14 private final int[] count = new int[4];
15 private int depth = 1;
16
17 private void m0() {
18 count[0]++;
19 dispatch();
20 }
21
22 private void m1() {
23 count[1]++;
24 dispatch();
25 }
26
27 private void m2() {
28 count[2]++;
29 dispatch();
30 }
31
32 private void m3() {
33 count[3]++;
34 dispatch();
35 }
36
37 private void dispatch() {
38 if (depth + 2 > BASE_DEPTH + ThreadLocalRandom.current().nextInt(VAR_DEPTH + 1)) {
39 return;
40 }
41
42 depth += 2;
43 switch (ThreadLocalRandom.current().nextInt(4)) {
44 case 0:
45 m0();
46 break;
47 case 1:
48 m1();
49 break;
50 case 2:
51 m2();
52 break;
53 case 3:
54 m3();
55 break;
56 }
57 depth -= 2;
58 }
59
60 public static void main(String[] args) throws Exception {
61 BASE_DEPTH = args.length > 0 ? Integer.parseInt(args[0]) : 100;
62 VAR_DEPTH = args.length > 1 ? Integer.parseInt(args[1]) : 0;
63 boolean print = args.length > 2 && Boolean.parseBoolean(args[2]);
64
65 DeepRecursion test = new DeepRecursion();
66 for (int i = 0; ; i++) {
67 test.dispatch();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected