| 12 | import java.util.Objects; |
| 13 | |
| 14 | public abstract class AInterpreter<T extends ACallFrame<T, U>, U extends ACompilerData<?, U>> |
| 15 | implements Evaluator { |
| 16 | |
| 17 | protected static final class ContinuationJump< |
| 18 | T extends ACallFrame<T, U>, U extends ACompilerData<?, U>> |
| 19 | implements Serializable { |
| 20 | private static final long serialVersionUID = 7687739156004308247L; |
| 21 | |
| 22 | T capturedFrame; |
| 23 | T branchFrame; |
| 24 | Object result; |
| 25 | double resultDbl; |
| 26 | |
| 27 | ContinuationJump(NativeContinuation c, T current) { |
| 28 | @SuppressWarnings("unchecked") |
| 29 | var cf = (T) c.getImplementation(); |
| 30 | capturedFrame = cf; |
| 31 | if (this.capturedFrame == null || current == null) { |
| 32 | // Continuation and current execution does not share |
| 33 | // any frames if there is nothing to capture or |
| 34 | // if there is no currently executed frames |
| 35 | this.branchFrame = null; |
| 36 | } else { |
| 37 | // Search for branch frame where parent frame chains starting |
| 38 | // from captured and current meet. |
| 39 | T chain1 = this.capturedFrame; |
| 40 | T chain2 = current; |
| 41 | |
| 42 | // First work parents of chain1 or chain2 until the same |
| 43 | // frame depth. |
| 44 | int diff = chain1.frameIndex - chain2.frameIndex; |
| 45 | if (diff != 0) { |
| 46 | if (diff < 0) { |
| 47 | // swap to make sure that |
| 48 | // chain1.frameIndex > chain2.frameIndex and diff > 0 |
| 49 | chain1 = current; |
| 50 | chain2 = this.capturedFrame; |
| 51 | diff = -diff; |
| 52 | } |
| 53 | do { |
| 54 | chain1 = chain1.parentFrame; |
| 55 | } while (--diff != 0); |
| 56 | if (chain1.frameIndex != chain2.frameIndex) Kit.codeBug(); |
| 57 | } |
| 58 | |
| 59 | // Now walk parents in parallel until a shared frame is found |
| 60 | // or until the root is reached. |
| 61 | while (!Objects.equals(chain1, chain2) && chain1 != null) { |
| 62 | chain1 = chain1.parentFrame; |
| 63 | chain2 = chain2.parentFrame; |
| 64 | } |
| 65 | |
| 66 | this.branchFrame = chain1; |
| 67 | if (this.branchFrame != null && !this.branchFrame.frozen) Kit.codeBug(); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 |
nothing calls this directly
no outgoing calls
no test coverage detected