summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-08-05 00:58:00 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2020-08-16 14:41:21 +0200
commit71aeedb6ec79a91e41251a88c1ab3235c40a9b70 (patch)
treea0160cb6eb6ddd7105318a9cf6e065b1d62742b8
parentdc856c28ba94a167aaf2483ff7dd1111cc57d977 (diff)
downloadjgit-71aeedb6ec79a91e41251a88c1ab3235c40a9b70.tar.gz
jgit-71aeedb6ec79a91e41251a88c1ab3235c40a9b70.zip
Delay WindowCache statistics JMX MBean registration
The WindowCache is configured statically with a default WindowCacheConfig. The default config says (for backwards compatibility reasons) to publish the MBean. As a result, the MBean always gets published. By delaying the MBean registration until the first call to getInstance() or get(PackFile, long) we can avoid the forced registration and do it only if not re-configured in the meantime not to publish the bean. (As is done by Egit, to avoid a very early costly access to the user and system config during plug-in activation.) Bug: 563740 Change-Id: I8a941342c0833acee2107515e64299aada7e0520 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java22
1 files changed, 15 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
index 80c8e10dec..3e8cb3a3f2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2008-2009, Google Inc.
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2009 Google Inc.
+ * Copyright (C) 2008, 2020 Shawn O. Pearce <spearce@spearce.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -19,6 +19,7 @@ import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.LongAdder;
@@ -376,14 +377,14 @@ public class WindowCache {
* @return the cached instance.
*/
public static WindowCache getInstance() {
- return cache;
+ return cache.publishMBeanIfNeeded();
}
static final ByteWindow get(PackFile pack, long offset)
throws IOException {
final WindowCache c = cache;
final ByteWindow r = c.getOrLoad(pack, c.toStart(offset));
- if (c != cache) {
+ if (c != cache.publishMBeanIfNeeded()) {
// The cache was reconfigured while we were using the old one
// to load this window. The window is still valid, but our
// cache may think its still live. Ensure the window is removed
@@ -433,6 +434,8 @@ public class WindowCache {
private final StatsRecorderImpl mbean;
+ private final AtomicBoolean publishMBean = new AtomicBoolean();
+
private boolean useStrongRefs;
private WindowCache(WindowCacheConfig cfg) {
@@ -470,9 +473,7 @@ public class WindowCache {
mbean = new StatsRecorderImpl();
statsRecorder = mbean;
- if (cfg.getExposeStatsViaJmx()) {
- Monitoring.registerMBean(mbean, "block_cache"); //$NON-NLS-1$
- }
+ publishMBean.set(cfg.getExposeStatsViaJmx());
if (maxFiles < 1)
throw new IllegalArgumentException(JGitText.get().openFilesMustBeAtLeast1);
@@ -480,6 +481,13 @@ public class WindowCache {
throw new IllegalArgumentException(JGitText.get().windowSizeMustBeLesserThanLimit);
}
+ private WindowCache publishMBeanIfNeeded() {
+ if (publishMBean.getAndSet(false)) {
+ Monitoring.registerMBean(mbean, "block_cache"); //$NON-NLS-1$
+ }
+ return this;
+ }
+
/**
* @return cache statistics for the WindowCache
*/