# HG changeset patch # User coffeys # Date 1400011177 -3600 # Node ID 1c91e3a7752d328f2c73cfcfec8cf1dd53b7fceb # Parent 1a30593dcb9802faec3b6edb24d86ca088594e4e 8042906: Remove use of reflection in ORB Reviewed-by: alanb, chegar, dfuchs, psandoz diff -r 1a30593dcb98 -r 1c91e3a7752d corba/src/share/classes/com/sun/corba/se/spi/orb/ORB.java --- a/corba/src/share/classes/com/sun/corba/se/spi/orb/ORB.java Wed Jul 05 19:40:19 2017 +0200 +++ b/corba/src/share/classes/com/sun/corba/se/spi/orb/ORB.java Tue May 13 20:59:37 2014 +0100 @@ -25,8 +25,6 @@ package com.sun.corba.se.spi.orb; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.Map ; import java.util.HashMap ; import java.util.Properties ; @@ -44,16 +42,13 @@ import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ; import com.sun.corba.se.spi.protocol.ClientDelegateFactory ; import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ; -import com.sun.corba.se.spi.protocol.CorbaMessageMediator ; import com.sun.corba.se.spi.protocol.PIHandler ; import com.sun.corba.se.spi.resolver.LocalResolver ; import com.sun.corba.se.spi.resolver.Resolver ; import com.sun.corba.se.spi.transport.CorbaContactInfoListFactory ; -import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo; import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager; import com.sun.corba.se.spi.monitoring.MonitoringConstants; import com.sun.corba.se.spi.monitoring.MonitoringManager; -import com.sun.corba.se.spi.monitoring.MonitoringManagerFactory; import com.sun.corba.se.spi.monitoring.MonitoringFactories; import com.sun.corba.se.spi.ior.IdentifiableFactoryFinder ; @@ -62,11 +57,6 @@ import com.sun.corba.se.spi.ior.ObjectKeyFactory ; import com.sun.corba.se.spi.ior.IOR ; -import com.sun.corba.se.spi.orbutil.closure.Closure ; - -import com.sun.corba.se.spi.orb.Operation ; -import com.sun.corba.se.spi.orb.ORBData ; -import com.sun.corba.se.spi.orb.ORBVersion ; import com.sun.corba.se.spi.orbutil.threadpool.ThreadPoolManager; import com.sun.corba.se.spi.oa.OAInvocationInfo ; @@ -99,8 +89,6 @@ import com.sun.corba.se.impl.presentation.rmi.PresentationManagerImpl ; -import sun.misc.JavaAWTAccess; - public abstract class ORB extends com.sun.corba.se.org.omg.CORBA.ORB implements Broker, TypeCodeFactory { @@ -146,9 +134,9 @@ // This map is needed for resolving recursive type code placeholders // based on the unique repository id. // XXX Should this be a WeakHashMap for GC? - private Map typeCodeMap ; + private Map typeCodeMap; - private TypeCodeImpl[] primitiveTypeCodeConstants ; + private TypeCodeImpl[] primitiveTypeCodeConstants; // ByteBufferPool - needed by both ORBImpl and ORBSingleton ByteBufferPool byteBufferPool; @@ -169,16 +157,18 @@ // wrapperMap maintains a table of LogWrapper instances used by // different classes to log exceptions. The key is a StringPair // representing LogDomain and ExceptionGroup. - private Map wrapperMap ; + private Map wrapperMap; static class Holder { static final PresentationManager defaultPresentationManager = setupPresentationManager(); } - private static final Map pmContexts = new HashMap<>(); + private static final Map pmContexts = + new ConcurrentHashMap<>(); - private static Map staticWrapperMap = new ConcurrentHashMap(); + private static Map staticWrapperMap = + new ConcurrentHashMap<>(); protected MonitoringManager monitoringManager; @@ -245,28 +235,12 @@ public static PresentationManager getPresentationManager() { SecurityManager sm = System.getSecurityManager(); - JavaAWTAccess javaAwtAccess = sun.misc.SharedSecrets.getJavaAWTAccess(); + sun.misc.JavaAWTAccess javaAwtAccess = sun.misc.SharedSecrets.getJavaAWTAccess(); if (sm != null && javaAwtAccess != null) { - Object appletContext; - try { - Class clazz = JavaAWTAccess.class; - Method method = clazz.getMethod("getAppletContext"); - appletContext = method.invoke(javaAwtAccess); - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - InternalError err = new InternalError(); - err.initCause(e); - throw err; - } - + final Object appletContext = javaAwtAccess.getAppletContext(); if (appletContext != null) { - synchronized (pmContexts) { - PresentationManager pm = pmContexts.get(appletContext); - if (pm == null) { - pm = setupPresentationManager(); - pmContexts.put(appletContext, pm); - } - return pm; - } + return pmContexts.computeIfAbsent(appletContext, + x -> setupPresentationManager()); } } @@ -290,13 +264,13 @@ { // Initialize logging first, since it is needed nearly // everywhere (for example, in TypeCodeImpl). - wrapperMap = new ConcurrentHashMap(); + wrapperMap = new ConcurrentHashMap<>(); wrapper = ORBUtilSystemException.get( this, CORBALogDomains.RPC_PRESENTATION ) ; omgWrapper = OMGSystemException.get( this, CORBALogDomains.RPC_PRESENTATION ) ; - typeCodeMap = new HashMap(); + typeCodeMap = new HashMap<>(); primitiveTypeCodeConstants = new TypeCodeImpl[] { new TypeCodeImpl(this, TCKind._tk_null), @@ -363,7 +337,7 @@ public synchronized TypeCodeImpl getTypeCode(String id) { checkShutdownState(); - return (TypeCodeImpl)typeCodeMap.get(id); + return typeCodeMap.get(id); } public MonitoringManager getMonitoringManager( ) { @@ -526,35 +500,23 @@ /** get the log wrapper class (its type is dependent on the exceptionGroup) for the * given log domain and exception group in this ORB instance. */ - public LogWrapperBase getLogWrapper( String logDomain, - String exceptionGroup, LogWrapperFactory factory ) + public LogWrapperBase getLogWrapper(String logDomain, + String exceptionGroup, LogWrapperFactory factory) { - StringPair key = new StringPair( logDomain, exceptionGroup ) ; - - LogWrapperBase logWrapper = (LogWrapperBase)wrapperMap.get( key ); - if (logWrapper == null) { - logWrapper = factory.create( getLogger( logDomain ) ); - wrapperMap.put( key, logWrapper ); - } - - return logWrapper; + return wrapperMap.computeIfAbsent( + new StringPair(logDomain, exceptionGroup), + x -> factory.create(getLogger(logDomain))); } /** get the log wrapper class (its type is dependent on the exceptionGroup) for the * given log domain and exception group in this ORB instance. */ - public static LogWrapperBase staticGetLogWrapper( String logDomain, - String exceptionGroup, LogWrapperFactory factory ) + public static LogWrapperBase staticGetLogWrapper(String logDomain, + String exceptionGroup, LogWrapperFactory factory) { - StringPair key = new StringPair( logDomain, exceptionGroup ) ; - - LogWrapperBase logWrapper = (LogWrapperBase)staticWrapperMap.get( key ); - if (logWrapper == null) { - logWrapper = factory.create( staticGetLogger( logDomain ) ); - staticWrapperMap.put( key, logWrapper ); - } - - return logWrapper; + return staticWrapperMap.computeIfAbsent( + new StringPair(logDomain, exceptionGroup), + x -> factory.create(staticGetLogger(logDomain))); } // get a reference to a ByteBufferPool, a pool of NIO ByteBuffers