Skip to content

Commit ffb7a61

Browse files
committed
Bug 38506522 - Significant Performance Regression due to getRunningNamedCache() change causing unnecessary heavy calls to DoAsAction.init
(merge 14.1.2-0 -> ce/14.1.2-0 118686) [git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v14.1.2.0/": change = 118691]
1 parent e8e592b commit ffb7a61

File tree

12 files changed

+215
-14
lines changed

12 files changed

+215
-14
lines changed

prj/coherence-core-21/src/main/java/com/tangosol/net/security/SecurityManagerWrapperImpl.java

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* <p>
2323
* This is a Java21 version of this class in the coherence-core-21
2424
* module and is built into the multi-release coherence.jar.
25-
*
25+
* <p>
2626
* Note, In case of Exception, Subject.callAs() wraps the Exception
2727
* returned by action::run with the java.util.concurrent.CompletionException.
2828
*
@@ -95,7 +95,30 @@ public void doIfSecure(PrivilegedAction<?> action, Runnable fallback)
9595
else
9696
{
9797
Subject subject = getCurrentSubject();
98-
AccessController.doPrivileged((PrivilegedAction) () ->
98+
AccessController.doPrivileged((PrivilegedAction<?>) () ->
99+
Subject.callAs(subject, action::run));
100+
}
101+
}
102+
else
103+
{
104+
fallback.run();
105+
}
106+
}
107+
108+
@Override
109+
public void doIfSecure(Supplier<PrivilegedAction<?>> supplier, Runnable fallback)
110+
{
111+
if (hasSecurityManager())
112+
{
113+
PrivilegedAction<?> action = supplier.get();
114+
if (action instanceof DoAsAction)
115+
{
116+
AccessController.doPrivileged(action);
117+
}
118+
else
119+
{
120+
Subject subject = getCurrentSubject();
121+
AccessController.doPrivileged((PrivilegedAction<?>) () ->
99122
Subject.callAs(subject, action::run));
100123
}
101124
}
@@ -121,6 +144,43 @@ public <T> T doIfSecure(PrivilegedAction<T> action, Supplier<T> fallback)
121144
return fallback.get();
122145
}
123146

147+
@Override
148+
public <T> T doIfSecureInDoAsAction(PrivilegedAction<T> action, Supplier<T> fallback)
149+
{
150+
if (hasSecurityManager())
151+
{
152+
return AccessController.doPrivileged(new DoAsAction<>(action));
153+
}
154+
return fallback.get();
155+
}
156+
157+
@Override
158+
public <T> T doIfSecureInDoAsAction(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback)
159+
{
160+
if (hasSecurityManager())
161+
{
162+
return AccessController.doPrivileged(new DoAsAction<>(supplier.get()));
163+
}
164+
return fallback.get();
165+
}
166+
167+
@Override
168+
public <T> T doIfSecure(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback)
169+
{
170+
if (hasSecurityManager())
171+
{
172+
PrivilegedAction<T> action = supplier.get();
173+
if (action instanceof DoAsAction)
174+
{
175+
return AccessController.doPrivileged(action);
176+
}
177+
Subject subject = getCurrentSubject();
178+
return AccessController.doPrivileged((PrivilegedAction<T>) () ->
179+
Subject.callAs(subject, action::run));
180+
}
181+
return fallback.get();
182+
}
183+
124184
@Override
125185
public <T> T doPrivileged(PrivilegedAction<T> action)
126186
{

prj/coherence-core-24/src/main/java/com/tangosol/net/security/SecurityManagerWrapperImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,36 @@ public void doIfSecure(PrivilegedAction<?> action, Runnable fallback)
6262
fallback.run();
6363
}
6464

65+
@Override
66+
public void doIfSecure(Supplier<PrivilegedAction<?>> action, Runnable fallback)
67+
{
68+
fallback.run();
69+
}
70+
6571
@Override
6672
public <T> T doIfSecure(PrivilegedAction<T> action, Supplier<T> fallback)
6773
{
6874
return fallback.get();
6975
}
7076

77+
@Override
78+
public <T> T doIfSecureInDoAsAction(PrivilegedAction<T> action, Supplier<T> fallback)
79+
{
80+
return fallback.get();
81+
}
82+
83+
@Override
84+
public <T> T doIfSecureInDoAsAction(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback)
85+
{
86+
return fallback.get();
87+
}
88+
89+
@Override
90+
public <T> T doIfSecure(Supplier<PrivilegedAction<T>> action, Supplier<T> fallback)
91+
{
92+
return fallback.get();
93+
}
94+
7195
@Override
7296
public <T> T doPrivileged(PrivilegedAction<T> action)
7397
{

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/SafeCluster.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
import com.tangosol.util.Base;
5050
import com.tangosol.util.SafeHashSet;
5151
import java.lang.ref.WeakReference;
52+
import java.security.PrivilegedAction;
5253
import java.util.Iterator;
5354
import java.util.Set;
5455
import java.util.concurrent.TimeUnit;
5556
import java.util.concurrent.locks.Lock;
57+
import java.util.function.Supplier;
5658

5759
/**
5860
* Cluster wrapper that never dies, unless explicitely commanded.
@@ -713,7 +715,7 @@ public com.tangosol.net.Service ensureService(String sName, String sType)
713715
action.setServiceName(sName);
714716
action.setServiceType(sType);
715717

716-
return (Service) SecurityHelper.doIfSecure(new DoAsAction(action), action::run);
718+
return (Service) SecurityHelper.doIfSecureInDoAsAction(action, action::run);
717719
}
718720

719721
// From interface: com.oracle.coherence.common.base.Lockable
@@ -942,7 +944,7 @@ public com.tangosol.net.management.Registry getManagement()
942944
*/
943945
public com.tangosol.coherence.component.net.Cluster getRunningCluster()
944946
{
945-
return SecurityHelper.doIfSecure(new DoAsAction(getEnsureClusterAction()), this::ensureRunningCluster);
947+
return SecurityHelper.doIfSecureInDoAsAction(getEnsureClusterAction(), this::ensureRunningCluster);
946948
}
947949

948950
// Accessor for the property "ScopedServiceStore"

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/SafeNamedCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ protected com.tangosol.net.cache.CacheStore getRunningCacheStore()
11541154
*/
11551155
protected com.tangosol.net.NamedCache getRunningNamedCache()
11561156
{
1157-
return SecurityHelper.doIfSecure(new DoAsAction(getEnsureCacheAction()), this::ensureRunningNamedCache);
1157+
return SecurityHelper.doIfSecureInDoAsAction(getEnsureCacheAction(), this::ensureRunningNamedCache);
11581158
}
11591159

11601160
// Accessor for the property "SafeAsyncNamedCache"

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/SafeService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ public com.tangosol.util.ResourceRegistry getResourceRegistry()
756756
*/
757757
public com.tangosol.util.Service getRunningService()
758758
{
759-
return SecurityHelper.doIfSecure(new DoAsAction(getEnsureServiceAction()), this::ensureRunningService);
759+
return SecurityHelper.doIfSecureInDoAsAction(getEnsureServiceAction(), this::ensureRunningService);
760760
}
761761

762762
// Accessor for the property "SafeCluster"

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/ShutdownHook.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import com.tangosol.net.security.SecurityHelper;
1515
import com.tangosol.util.Base;
1616

17+
import java.security.PrivilegedAction;
18+
import java.util.function.Supplier;
19+
1720
/**
1821
* Abstract runnable component used as a virtual-machine shutdown hook.
1922
*/
@@ -182,8 +185,8 @@ public void setThread(Thread thread)
182185
*/
183186
public void unregister()
184187
{
185-
SecurityHelper.doIfSecure(new DoAsAction((ShutdownHook.UnregisterAction) _newChild("UnregisterAction")),
186-
this::unregisterInternal);
188+
Supplier<PrivilegedAction<?>> supplier = () -> new DoAsAction<>((ShutdownHook.UnregisterAction) _newChild("UnregisterAction"));
189+
SecurityHelper.doIfSecure(supplier, this::unregisterInternal);
187190
}
188191

189192
/**

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/daemon/queueProcessor/service/grid/partitionedService/PartitionedCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24158,7 +24158,7 @@ public com.tangosol.util.InvocableMap.Entry getReadOnlyEntry(Object oKey)
2415824158
Storage storage = getStorage();
2415924159
Map mapStatus = (Map) ctx.getStorageStatusMap().get(storage);
2416024160

24161-
Map mapResource = SecurityHelper.doIfSecure(new DoAsAction(storage.getBackingMapAction()),
24161+
Map mapResource = SecurityHelper.doIfSecureInDoAsAction(storage.getBackingMapAction(),
2416224162
storage::getBackingMapInternal);
2416324163

2416424164
Storage.EntryStatus status = mapStatus == null ? null : (Storage.EntryStatus) mapStatus.get((Binary) oKey);

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/util/daemon/queueProcessor/service/grid/partitionedService/partitionedCache/Storage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12942,7 +12942,7 @@ public com.tangosol.net.BackingMapContext getBackingMapContext()
1294212942
protected com.tangosol.util.ObservableMap getBackingMapInternal()
1294312943
{
1294412944
Storage storage = getStorage();
12945-
return SecurityHelper.doIfSecure(storage.getBackingMapAction(), storage::getBackingMap);
12945+
return SecurityHelper.doIfSecureInDoAsAction(storage.getBackingMapAction(), storage::getBackingMap);
1294612946
}
1294712947

1294812948
// From interface: com.tangosol.util.BinaryEntry

prj/coherence-core/src/main/java/com/tangosol/net/ExtensibleConfigurableCacheFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,9 @@ public <V> NamedTopic<V> ensureTopic(String sName, ClassLoader loader, NamedTopi
437437

438438
Base.checkNotEmpty(sName, "name");
439439

440-
PrivilegedAction<NamedTopic> action =
441-
() -> ensureCollectionInternal(sName, NamedTopic.class, loader, f_storeTopics, TopicMapping.class, options);
442-
443-
return SecurityHelper.doPrivileged(new DoAsAction<>(action));
440+
return SecurityHelper.hasSecurityManager()
441+
? SecurityHelper.doPrivileged(new DoAsAction<>(() -> ensureCollectionInternal(sName, NamedTopic.class, loader, f_storeTopics, TopicMapping.class, options)))
442+
: ensureCollectionInternal(sName, NamedTopic.class, loader, f_storeTopics, TopicMapping.class, options);
444443
}
445444

446445
<C extends NamedCollection, M extends TypedResourceMapping, V>

prj/coherence-core/src/main/java/com/tangosol/net/security/SecurityHelper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,31 @@ public static void doIfSecure(PrivilegedAction<?> action, Runnable fallback)
5757
s_securityManager.doIfSecure(action, fallback);
5858
}
5959

60+
public static void doIfSecure(Supplier<PrivilegedAction<?>> action, Runnable fallback)
61+
{
62+
s_securityManager.doIfSecure(action, fallback);
63+
}
64+
6065
public static <T> T doIfSecure(PrivilegedAction<T> action, Supplier<T> fallback)
6166
{
6267
return s_securityManager.doIfSecure(action, fallback);
6368
}
6469

70+
public static <T> T doIfSecureInDoAsAction(PrivilegedAction<T> action, Supplier<T> fallback)
71+
{
72+
return s_securityManager.doIfSecureInDoAsAction(action, fallback);
73+
}
74+
75+
public static <T> T doIfSecureInDoAsAction(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback)
76+
{
77+
return s_securityManager.doIfSecureInDoAsAction(supplier, fallback);
78+
}
79+
80+
public static <T> T doIfSecure(Supplier<PrivilegedAction<T>> supplier, Supplier<T> fallback)
81+
{
82+
return s_securityManager.doIfSecure(supplier, fallback);
83+
}
84+
6585
public static <T> T doPrivileged(PrivilegedAction<T> action)
6686
{
6787
return s_securityManager.doPrivileged(action);

0 commit comments

Comments
 (0)