comparison c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/LoggingProxy.java @ 1422:3483ec571caf

* using reflected objects instead of oops * removed scratch from allocatable registers * instanceof xir snippet * arraylength xir snippet * exceptionobject xir snippet * VMEntries and VMExits as interfaces * calls to VMEntries and VMExits are routet through logging proxies
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 02 Aug 2010 15:44:38 -0700
parents 6223633ce7dd
children
comparison
equal deleted inserted replaced
1421:6223633ce7dd 1422:3483ec571caf
13 @Override 13 @Override
14 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 14 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
15 int argCount = args == null ? 0 : args.length; 15 int argCount = args == null ? 0 : args.length;
16 if (method.getParameterTypes().length != argCount) 16 if (method.getParameterTypes().length != argCount)
17 throw new RuntimeException("wrong parameter count"); 17 throw new RuntimeException("wrong parameter count");
18 System.out.println("method " + method + " called with " + argCount + " args"); 18 StringBuilder str = new StringBuilder();
19 if (args == null) 19 str.append(method.getReturnType().getSimpleName() + " " + method.getDeclaringClass().getSimpleName() + "." + method.getName() + "(");
20 return method.invoke(delegate); 20 for (int i = 0; i < argCount; i++) {
21 return method.invoke(delegate, args); 21 str.append(i == 0 ? "" : ", ");
22 str.append(Logger.pretty(args[i]));
23 }
24 str.append(")");
25 Logger.startScope(str.toString());
26 final Object result;
27 if (args == null) {
28 result = method.invoke(delegate);
29 } else {
30 result = method.invoke(delegate, args);
31 }
32 Logger.endScope(" = " + Logger.pretty(result));
33 return result;
22 } 34 }
23 35
24 public static <T> T getProxy(Class<T> interf, T delegate) { 36 public static <T> T getProxy(Class<T> interf, T delegate) {
25 Object obj = Proxy.newProxyInstance(interf.getClassLoader(), new Class[] { interf}, new LoggingProxy<T>(delegate)); 37 Object obj = Proxy.newProxyInstance(interf.getClassLoader(), new Class[] { interf}, new LoggingProxy<T>(delegate));
26 return interf.cast(obj); 38 return interf.cast(obj);