Security manager benchmarking

Gary Benson gbenson@redhat.com
Wed Aug 23 10:25:00 GMT 2006


Hi all,

Andrew Haley asked me about the Tomcat benchmark I've been using to
identify bottlenecks caused by enabling a security manager.  I thought
I'd post the details here in case anyone else is interested in them.

The short story is I build gcj with the attached patch which allows
user code to disable parts of the security architecture.  I run Tomcat
with this, BC compiled, and with a security manager enabled.  I use
the attached webapp to select how much of the security manager I want
to use, and I run ApacheBench (the Apache HTTP server benchmarking
tool) on it.

The details (somewhat Fedora specific):
 Building gcj:
   Apply gcj-benchmark-hacks.patch and build :) FWIW I installed it in
   /opt/gcc and did rpm -e libgcj-devel to make sure I wasn't picking
   up anything from that.  After you install you have to copy
   /usr/lib/security/*.security into /opt/gcc/lib/security.

 Building java-1.4.2-gcj-compat:
   I built a custom java-1.4.2-gcj-compat rpm using jgc-hacks.patch.

 Installing Tomcat:
   yum install tomcat5-webapps tomcat5-admin-webapps
   Apply tomcat5-init.patch to /etc/init.d/tomcat5.

   I'm not sure if it's necessary but I rebuilt all the BC libraries
   with my custom gcj.  Note that gcj's make install will trash your
   classmap.db, so you need to re-run rebuild-gcj-db every time.

 Installing the webapp:
   You can't deploy using the manager on Fedora unfortunatly, so this
   is a manual thing.

     mkdir /var/lib/tomcat5/webapps/test
     cd $_
     jar xf test.war

 Start Tomcat:
   service tomcat5 start

 Benchmark:
   Check the webapp is running with GET http://localhost:8080/test
   Change settings with GET http://localhost:8080/test?command=clear etc
     (or just use a browser)
   Benchmark with ab -c10 -n100000 http://localhost:8080/test
   The first run should be ignored as: it will be significantly slower
   because the server will not have warmed up.

The different settings are:
  Security manager is set / AccessController is enabled
    This is normal "with a security manager" operation

  Security manager is null / AccessController is enabled
    This is normal "without a security manager" operation

  Security manager is set / AccessController is disabled
    This disables AccessController.getContext().  The drop in
    performance between this and "set/enabled" is due to all the
    stuff that happens in all the if (securitymanager != null)
    blocks.

  Security manager is null / AccessController is disabled
    This is pretty meaningless.
    
Enjoy :)

Gary
-------------- next part --------------
Index: java/lang/System.java
===================================================================
--- java/lang/System.java	(revision 116080)
+++ java/lang/System.java	(working copy)
@@ -175,9 +175,8 @@
     // Implementation note: the field lives in SecurityManager because of
     // bootstrap initialization issues. This method is synchronized so that
     // no other thread changes it to null before this thread makes the change.
-    if (SecurityManager.current != null)
-      SecurityManager.current.checkPermission
-        (new RuntimePermission("setSecurityManager"));
+    if (sm == null && SecurityManager.current != null)
+      SecurityManager.saved = SecurityManager.current;
     SecurityManager.current = sm;
   }
 
Index: java/lang/SecurityManager.java
===================================================================
--- java/lang/SecurityManager.java	(revision 116080)
+++ java/lang/SecurityManager.java	(working copy)
@@ -138,6 +138,8 @@
    */
   static volatile SecurityManager current;
 
+  public static SecurityManager saved;
+
   /**
    * Tells whether or not the SecurityManager is currently performing a
    * security check.
Index: java/security/VMAccessController.java
===================================================================
--- java/security/VMAccessController.java	(revision 116128)
+++ java/security/VMAccessController.java	(working copy)
@@ -138,6 +138,9 @@
    */
   static AccessControlContext getContext()
   {
+    if (!AccessController.enabled)
+      return DEFAULT_CONTEXT;
+    
     // If the VM is initializing return the all-permissive context
     // so that any security checks succeed.
     VMAccessControlState state = VMAccessControlState.getThreadState();
Index: classpath/java/security/AccessController.java
===================================================================
--- classpath/java/security/AccessController.java	(revision 116080)
+++ classpath/java/security/AccessController.java	(working copy)
@@ -53,6 +53,8 @@
  */
 public final class AccessController
 {
+  public static boolean enabled = true;
+  
   /**
    * This class only has static methods so there is no public contructor.
    */
-------------- next part --------------
Index: java-1.4.2-gcj-compat.spec
===================================================================
RCS file: /cvs/dist/rpms/java-1.4.2-gcj-compat/devel/java-1.4.2-gcj-compat.spec,v
retrieving revision 1.166
diff -u -r1.166 java-1.4.2-gcj-compat.spec
--- java-1.4.2-gcj-compat.spec	14 Aug 2006 18:59:44 -0000	1.166
+++ java-1.4.2-gcj-compat.spec	23 Aug 2006 09:58:05 -0000
@@ -1,7 +1,8 @@
 %define section		free
 
-%{!?custom:	%define custom 0}
-%{!?gcjprefix: 	%define gcjprefix %{nil}}
+%define custom 1
+%define gcjprefix /opt/gcc
+%define gcj_prefix /opt/gcc
 %{!?origin:	%{expand: %%define origin gcj%{gccsuffix}}}
 %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
 %define gccsuffix	%{nil}
@@ -173,13 +174,13 @@
 
 make DESTDIR=$RPM_BUILD_ROOT install
 
-%if %{custom}
-rm -f $RPM_BUILD_ROOT%{_bindir}/aot-compile-rpm
-rm -f $RPM_BUILD_ROOT%{_bindir}/rebuild-gcj-db
-rm -f $RPM_BUILD_ROOT%{_bindir}/aot-compile
-rm -f $RPM_BUILD_ROOT%{python_sitelib}/aotcompile.py*
-rm -f $RPM_BUILD_ROOT%{python_sitelib}/classfile.py*
-%endif
+#%if %{custom}
+#rm -f $RPM_BUILD_ROOT%{_bindir}/aot-compile-rpm
+#rm -f $RPM_BUILD_ROOT%{_bindir}/rebuild-gcj-db
+#rm -f $RPM_BUILD_ROOT%{_bindir}/aot-compile
+#rm -f $RPM_BUILD_ROOT%{python_sitelib}/aotcompile.py*
+#rm -f $RPM_BUILD_ROOT%{python_sitelib}/classfile.py*
+#%endif
 
 %if %{custom}
 ln -sf %{_bindir}/ecj-%{cname} $RPM_BUILD_ROOT%{_jvmdir}/%{sdkdir}/bin/javac
@@ -597,9 +598,9 @@
 %doc
 %dir %{_jvmdir}/%{sdkdir}
 %dir %{jvmjardir}
-%if ! %{custom}
+#%if ! %{custom}
 %{_bindir}/rebuild-gcj-db
-%endif
+#%endif
 %{jvmjardir}/*.jar
 %{_jvmdir}/%{jrelnk}
 %{_jvmjardir}/%{jrelnk}
@@ -621,12 +622,12 @@
 %defattr(-,root,root)
 %doc
 %dir %{_jvmdir}/%{sdkdir}/bin
-%if ! %{custom}
+#%if ! %{custom}
 %{_bindir}/aot-compile
 %{_bindir}/aot-compile-rpm
 %{python_sitelib}/aotcompile.py*
 %{python_sitelib}/classfile.py*
-%endif
+#%endif
 %{_jvmdir}/%{sdkdir}/lib
 %{_jvmdir}/%{sdkdir}/include
 %{_jvmdir}/%{sdklnk}
-------------- next part --------------
--- /etc/init.d/tomcat5~	2006-03-06 23:18:32.000000000 +0000
+++ /etc/init.d/tomcat5	2006-08-07 10:21:44.000000000 +0100
@@ -99,9 +99,9 @@
         $TOMCAT_RELINK_SCRIPT
 
         if [ -x /etc/rc.d/init.d/functions ]; then
-        	daemon --user $TOMCAT_USER $TOMCAT_SCRIPT start 
+        	daemon --user $TOMCAT_USER $TOMCAT_SCRIPT start -security
     	else
-        	$SU - $TOMCAT_USER -c "$TOMCAT_SCRIPT start"
+        	$SU - $TOMCAT_USER -c "$TOMCAT_SCRIPT start -security"
     	fi
 
     	RETVAL=$?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.war
Type: application/octet-stream
Size: 5172 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20060823/14d51d8e/attachment.obj>


More information about the Java mailing list