|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2017 Microsoft Corporation and others. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | + * Microsoft Corporation - initial API and implementation |
| 10 | + *******************************************************************************/ |
| 11 | + |
| 12 | +package com.microsoft.java.debug.core.adapter; |
| 13 | + |
| 14 | +import java.util.Collections; |
| 15 | +import java.util.HashMap; |
| 16 | +import java.util.Map; |
| 17 | + |
| 18 | +import com.microsoft.java.debug.core.adapter.variables.StackFrameReference; |
| 19 | +import com.sun.jdi.IncompatibleThreadStateException; |
| 20 | +import com.sun.jdi.StackFrame; |
| 21 | +import com.sun.jdi.ThreadReference; |
| 22 | + |
| 23 | +public class StackFrameManager implements IStackFrameManager { |
| 24 | + private Map<Long, StackFrame[]> threadStackFrameMap = Collections.synchronizedMap(new HashMap<>()); |
| 25 | + |
| 26 | + @Override |
| 27 | + public StackFrame getStackFrame(StackFrameReference ref) { |
| 28 | + ThreadReference thread = ref.getThread(); |
| 29 | + int depth = ref.getDepth(); |
| 30 | + StackFrame[] frames = threadStackFrameMap.get(thread.uniqueID()); |
| 31 | + return frames == null || frames.length < depth ? null : frames[depth]; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public StackFrame[] reloadStackFrames(ThreadReference thread) { |
| 36 | + return threadStackFrameMap.compute(thread.uniqueID(), (key, old) -> { |
| 37 | + try { |
| 38 | + return thread.frames().toArray(new StackFrame[0]); |
| 39 | + } catch (IncompatibleThreadStateException e) { |
| 40 | + return new StackFrame[0]; |
| 41 | + } |
| 42 | + }); |
| 43 | + } |
| 44 | +} |
0 commit comments