pass FJP a fake thread factory to diagnose cases of too early FJP initialization

This commit is contained in:
Alexey Kudravtsev
2017-12-01 18:02:38 +03:00
parent ed75faa323
commit b30f70fdd0
5 changed files with 34 additions and 0 deletions
@@ -37,6 +37,13 @@ public class IdeaForkJoinWorkerThreadFactory implements ForkJoinPool.ForkJoinWor
}
}
public static void setupPoisonFactory() {
// if this method is called early enough and app called setupForkJoinCommonPool() too late
// (setupForkJoinCommonPool() has to be called after Main.setFlags() but before FJP init)
// then on the first use the FJP will explode, revealing who did the too early FJP init
System.setProperty("java.util.concurrent.ForkJoinPool.common.threadFactory", PoisonFactory.class.getName());
}
private static final AtomicLong bits = new AtomicLong();
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
@@ -0,0 +1,19 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.concurrency;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinWorkerThread;
public class PoisonFactory implements ForkJoinPool.ForkJoinWorkerThreadFactory{
public PoisonFactory() {
RuntimeException exception = new RuntimeException("ForkJoinPool initialized too early, IdeaForkJoinWorkerThreadFactory ignored");
exception.printStackTrace();
exception.printStackTrace(System.out);
throw exception;
}
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
throw new RuntimeException();
}
}
@@ -1,6 +1,7 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.idea;
import com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory;
import com.intellij.ide.cloudConfig.CloudConfigProvider;
import com.intellij.ide.customize.CustomizeIDEWizardDialog;
import com.intellij.ide.customize.CustomizeIDEWizardStepsProvider;
@@ -74,6 +75,7 @@ public class StartupUtil {
}
static void prepareAndStart(String[] args, AppStarter appStarter) {
IdeaForkJoinWorkerThreadFactory.setupPoisonFactory();
boolean newConfigFolder = false;
if (!Main.isHeadless()) {
@@ -87,6 +87,7 @@ public abstract class UsefulTestCase extends TestCase {
private static final Map<String, Long> TOTAL_TEARDOWN_COST_MILLIS = new HashMap<>();
static {
IdeaForkJoinWorkerThreadFactory.setupPoisonFactory();
Logger.setFactory(TestLoggerFactory.class);
}
protected static final Logger LOG = Logger.getInstance(UsefulTestCase.class);
@@ -15,6 +15,7 @@
*/
package com.intellij.testFramework.fixtures.impl;
import com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.testFramework.EdtTestUtil;
@@ -31,6 +32,10 @@ public class BaseFixture implements IdeaTestFixture {
private boolean myDisposed;
private final Disposable myTestRootDisposable = Disposer.newDisposable();
static {
IdeaForkJoinWorkerThreadFactory.setupPoisonFactory();
}
@Override
public void setUp() throws Exception {
Assert.assertFalse("setUp() already has been called", myInitialized);