Re: [jboss-dev-forums] [JBoss Microcontainer Development] - JBoss Reflect Performance Javassist vs Introspection
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"JBoss Reflect Performance Javassist vs Introspection"
To view the discussion, visit: http://community.jboss.org/message/537798#537798
--------------------------------------------------------------
I have done some performance measurements where I compare the times taken creating the following class, using javassist.bytecode.* and asm
public class JavassistMethod1 implements JavassistMethod
{
public Object invoke(Object target, Object[] args) throws Throwable
{
return Integer.valueOf(((SomeClass)target).someMethod(((Integer)args[0]).intValue(), (String)args[1])).intValue();
}
}
Which would be used to call the method:
int someMethod(int i, String);
The basic flow for what I do for both approaches is the same, whereby I do the following lots of times to generate lots of similar classes:
A) - Create class structure
B) - Add default constructor with body to call super
C) - Add invoke method
C1) - Add invoke method body
D) - Convert class structure from A) into byte[]
E) - Define java.lang.Class by calling ClassLoader.defineClass()
F) - Call Class.newInstance()
1 - Average times (ms) to do A-F is:
|| *Classes* || *ASM* || *Javassist* || *ASM/Javassist* ||
| 10000 | 1079 | 1585 | .68 |
| 15000 | 1550 | 2153 | .72 |
| 20000 | 1901 | 2665 | .71 |
2 - Taking the instantiation out of the equation, so we just do A-E:
|| *Classes* || *ASM* || *Javassist* || ASM/Javassist ||
| 20000 | 1290 | 1998 | .64 |
3 - Not loading the class, so we do A-D:
|| *Classes* || *ASM* || *Javassist* || *ASM/Javassist* ||
| 20000 | 391 | 1115 | .35 |
| 40000 | 499 | 1489 | .34 |
4 - Just doing A-C shows that javassist has a massive overhead in step D:
|| *Classes* || ASM || *Javsssist* || *ASM/Javassist* ||
| 40000 | 524 | 747 | .71 |
| 100000 | 823 | 1244 | .66 |
5 - Doing A-C with a simplified method body in C1 so it is just the equivalent of {return null;}:
|| Classes || *ASM* || *Javassist* || *ASM/Javassist* ||
| 40000 | 494 | 617 | .80 |
| 100000 | 723 | 923 | .78 |
6 - If I don't create the method in C at all, so I just do A-B
|| *Classes* || ASM || Javassist || ASM/Javassist ||
| 40000 | 449 | 589 | .76 |
| 100000 | 619 | 845 | .73 |
So unfortunately Javassist is slower than ASM when it comes to creating new classes. Both at generating the bytecode, and a lot slower at converting the javassist.bytecode.ClassFile to a byte[].
The other overhead in this, as mentioned in a previous post, is the actual loading and instantiation of the classes themselves. So, I think generating less classes that do more stuff is the way forward, although that means a bigger overhead in creating the methods which will be bigger. I will play with creating an asm version of that.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/537798#537798]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 11 months
Re: [jboss-dev-forums] [JBoss Web Services Development] - JBWS-2210 : CXF Username Token JAAS integration
by Sergey Beryozkin
Sergey Beryozkin [http://community.jboss.org/people/sergeyb] replied to the discussion
"JBWS-2210 : CXF Username Token JAAS integration"
To view the discussion, visit: http://community.jboss.org/message/537517#537517
--------------------------------------------------------------
Hi
I've created the initial patch for [1].
The reason it has to be a patch is that JBossCXF currently depends on CXF 2.2.6 while the system test which I've added depends on CXF 2.2.8-SNAPSHOT.
The [UsernameAuthorizingTestCase] test is quite simple but it demonstrates the idea of separating authentication and authorization actions into separate phases.
SubjectCreatingInterceptor extends [2] and authenticates and populates a Subject using a (legacy) JBossSX api which will need to be updated to use PicketBox API. SubjectCreatingInterceptor could've also overridden a createSecurityContext() from its superclass if the default SecurityContext.isUserInRole was not working (but it does in this case). Eventually this interceptor should likely make it into JBossCXF/trunk/src/main. At the moment some of the code required to deal with digests is missing, it is commented out but classes like NonceStore can be ported from JBossNative.
Finally, CXF-based interceptor [3] is used to authorize the requests, here is a sample configuration :
<util:map id="methodPermissions">
<entry key="sayHello" value="friend colleague"/>
<entry key="greetMe" value="snoopies"/>
</util:map>
<bean id="AuthorizeIn" class="org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor">
<property name="methodRolesMap" ref="methodPermissions"/>
</bean>
Other authorizing interceptors can be added easily. For example, one can extend SimpleAuthorizingInterceptor and set a property identifying a service class on it. The setter would load and introspect a class for @RolesAllowed, @DenyAll, etc and set a roles map on the superclass. [4] can also be extended if say PicketBox AuthorizationManager were to be used.
One thing which will need to be addressed at CXF level is a policy-first case, where interceptors are added by the policy runtime, so some work has to be done to ensure interceptors like SubjectCreatingInterceptor can be added when needed too.I'm planning to investigate what needs to be done...
Any comments - let me know please
cheers, Sergey
[1] https://jira.jboss.org/jira/browse/JBWS-2210 https://jira.jboss.org/jira/browse/JBWS-2210
[2] http://svn.apache.org/repos/asf/cxf/trunk/rt/ws/security/src/main/java/or... http://svn.apache.org/repos/asf/cxf/trunk/rt/ws/security/src/main/java/or...
[3] http://svn.apache.org/repos/asf/cxf/trunk/rt/core/src/main/java/org/apach... http://svn.apache.org/repos/asf/cxf/trunk/rt/core/src/main/java/org/apach...
[4] http://svn.apache.org/repos/asf/cxf/trunk/rt/core/src/main/java/org/apach... http://svn.apache.org/repos/asf/cxf/trunk/rt/core/src/main/java/org/apach...
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/537517#537517]
Start a new discussion in JBoss Web Services Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 11 months
Re: [jboss-dev-forums] [JBoss Microcontainer Development] - JBoss Reflect Performance Javassist vs Introspection
by Kabir Khan
Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion
"JBoss Reflect Performance Javassist vs Introspection"
To view the discussion, visit: http://community.jboss.org/message/537476#537476
--------------------------------------------------------------
What we generate is effectively something along the lines of
public class JavassistMethod1 implements JavassistMethod
{
public Object invoke(Object target, Object[] args) throws Throwable
{
if (target == null)
throw new IllegalArgumentException("Null target");
if (target instanceof SomeClass == false)
throw new IllegalArgumentException("Wrong target");
if (args == null || args.length != 10)
throw new IllegalArgumentException("Wrong number of parameters");
if (args[0] == null)
throw new IllegalArgumentException("Parameter 1 cannot be null for SomeClass.someMethod(long, String)");
if (args[0] != null && args[0] instanceof Long == false)
throw new IllegalArgumentException("Parameter 1 is not an instance of Long for SomeClass.someMethod(long, String)");
if (args[1] != null && args[1] instanceof String == false)
throw new IllegalArgumentException("Parameter 2 is not an instance of String for SomeClass.someMethod(long, String)");
return ((SomeClass)target).someMethod(((Long)args[0]).longValue(), (String)args[1]);
}
}
Disabling the parameter checking so we end up with this instead reduces the time spent in C from about 4.8s to 3.8s
public class JavassistMethod1 implements JavassistMethod
{
public Object invoke(Object target, Object[] args) throws Throwable
{
return ((SomeClass)target).someMethod(((Long)args[0]).longValue(), (String)args[1]);
}
}
Profiling this, for each JavassistMethod implementation the time taken is roughly
50% generating the bytecode for the method
30% Converting the bytecode to a byte array and creating the class
13% creating the constructor
6% setting the interfaces
Maybe a better approach would be
1) to do the parameter checking in Javassist[Constructor/Method/Field]Info itself
2) to generate less classes? Something like:
public class SomeBeanAccessor implements JavassistBeanAccessor
{
public Object newInstance(int index, Object[] args) throws Throwable
{
if (index == 0)
return new SomeClass((String)args[0]);
else if (index == 1)
return new SomeClass((String)args[1]);
return null;
}
public Object invoke(long hash, Object target, Object[] args) throws Throwable
{
if (hash == 121267912)
return ((SomeClass)target).someMethod(((Long)args[0]).longValue(), (String)args[1]);
if (hash == 128172981)
return ((SomeClass)target).otherMethod(((Long)args[0]).longValue(), (String)args[1], (String)args[2]);
}
public Object get(String name, Object target) throws Throwable
{
if (name.equals("intField")
return Integer.valueOf(((SomeClass)target).intField);
if (name.equals("stringField")
return ((SomeClass)target).stringField;
}
public void set(String name, Object target, Object value) throws Throwable
{
if (name.equals("intField")
((SomeClass)target).intField = ((Integer)value).intValue();
return;
if (name.equals("stringField")
((SomeClass)target).stringField = (String)value;
}
}
First call by Javassist[Constructor/Method/Field]Info to access the member would result in this being created for ALL members, and cached in JavassistTypeInfo.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/537476#537476]
Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&cont...]
15 years, 11 months