diff --git a/java/debugger/impl/src/com/intellij/debugger/DebugEnvironment.java b/java/debugger/impl/src/com/intellij/debugger/DebugEnvironment.java index 3a0e58cd8311..f194cb3a0959 100644 --- a/java/debugger/impl/src/com/intellij/debugger/DebugEnvironment.java +++ b/java/debugger/impl/src/com/intellij/debugger/DebugEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,8 @@ import org.jetbrains.annotations.Nullable; */ public interface DebugEnvironment { + int LOCAL_START_TIMEOUT = 30000; + @Nullable ExecutionResult createExecutionResult() throws ExecutionException; @@ -38,7 +40,17 @@ public interface DebugEnvironment { RemoteConnection getRemoteConnection(); - boolean isPollConnection(); + /** + * @deprecated use {@link #getPollTimeout()} + */ + default boolean isPollConnection() { + return false; + } + + default long getPollTimeout() { + //noinspection deprecation + return isPollConnection() ? LOCAL_START_TIMEOUT : 0; + } String getSessionName(); } diff --git a/java/debugger/impl/src/com/intellij/debugger/DefaultDebugEnvironment.java b/java/debugger/impl/src/com/intellij/debugger/DefaultDebugEnvironment.java index b98bd4c9509c..5cfee964e7d6 100644 --- a/java/debugger/impl/src/com/intellij/debugger/DefaultDebugEnvironment.java +++ b/java/debugger/impl/src/com/intellij/debugger/DefaultDebugEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,16 +27,23 @@ import org.jetbrains.annotations.NotNull; public class DefaultDebugEnvironment implements DebugEnvironment { private final GlobalSearchScope mySearchScope; private final RemoteConnection myRemoteConnection; - private final boolean myPollConnection; + private final long myPollTimeout; private final ExecutionEnvironment environment; private final RunProfileState state; private final boolean myNeedParametersSet; public DefaultDebugEnvironment(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state, RemoteConnection remoteConnection, boolean pollConnection) { + this(environment, state, remoteConnection, pollConnection ? LOCAL_START_TIMEOUT : 0); + } + + public DefaultDebugEnvironment(@NotNull ExecutionEnvironment environment, + @NotNull RunProfileState state, + RemoteConnection remoteConnection, + long pollTimeout) { this.environment = environment; this.state = state; myRemoteConnection = remoteConnection; - myPollConnection = pollConnection; + myPollTimeout = pollTimeout; mySearchScope = SearchScopeProvider.createSearchScope(environment.getProject(), environment.getRunProfile()); myNeedParametersSet = remoteConnection.isServerMode() && remoteConnection.isUseSockets() && "0".equals(remoteConnection.getAddress()); @@ -72,8 +79,8 @@ public class DefaultDebugEnvironment implements DebugEnvironment { } @Override - public boolean isPollConnection() { - return myPollConnection; + public long getPollTimeout() { + return myPollTimeout; } @Override diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java index a98aacf5cf4f..0a46fc0d296f 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessImpl.java @@ -129,7 +129,6 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb private final SuspendManagerImpl mySuspendManager = new SuspendManagerImpl(this); protected CompoundPositionManager myPositionManager = null; private final DebuggerManagerThreadImpl myDebuggerManagerThread; - private static final int LOCAL_START_TIMEOUT = 30000; private final Semaphore myWaitFor = new Semaphore(); private final AtomicBoolean myIsFailed = new AtomicBoolean(false); @@ -1839,7 +1838,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb myState.set(State.INITIAL); myConnection = environment.getRemoteConnection(); getManagerThread().restartIfNeeded(); - createVirtualMachine(environment.getSessionName(), environment.isPollConnection()); + createVirtualMachine(environment); }); } }); @@ -1856,7 +1855,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb myConnection = environment.getRemoteConnection(); - createVirtualMachine(environment.getSessionName(), environment.isPollConnection()); + createVirtualMachine(environment); ExecutionResult executionResult; try { @@ -1919,7 +1918,9 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } } - private void createVirtualMachine(final String sessionName, final boolean pollConnection) { + private void createVirtualMachine(final DebugEnvironment environment) { + final String sessionName = environment.getSessionName(); + final long pollTimeout = environment.getPollTimeout(); final Semaphore semaphore = new Semaphore(); semaphore.down(); @@ -1943,13 +1944,13 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb try { final long time = System.currentTimeMillis(); - while (System.currentTimeMillis() - time < LOCAL_START_TIMEOUT) { + do { try { vm = createVirtualMachineInt(); break; } catch (final ExecutionException e) { - if (pollConnection && !myConnection.isServerMode() && e.getCause() instanceof IOException) { + if (pollTimeout > 0 && !myConnection.isServerMode() && e.getCause() instanceof IOException) { synchronized (this) { try { wait(500); @@ -1973,6 +1974,7 @@ public abstract class DebugProcessImpl extends UserDataHolderBase implements Deb } } } + while (System.currentTimeMillis() - time < pollTimeout); } finally { semaphore.up(); diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java index 1a2f1442cb67..e30b4a18a563 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/GenericDebuggerRunner.java @@ -100,7 +100,16 @@ public class GenericDebuggerRunner extends JavaPatchableProgramRunner