(ClassLoader loader,
Class[] interfaces,
String name)
| 355 | } |
| 356 | |
| 357 | private static Class makeClass(ClassLoader loader, |
| 358 | Class[] interfaces, |
| 359 | String name) |
| 360 | throws IOException |
| 361 | { |
| 362 | List<PoolEntry> pool = new ArrayList(); |
| 363 | |
| 364 | int[] interfaceIndexes = new int[interfaces.length]; |
| 365 | for (int i = 0; i < interfaces.length; ++i) { |
| 366 | interfaceIndexes[i] = ConstantPool.addClass |
| 367 | (pool, interfaces[i].getName().replace('.', '/')); |
| 368 | } |
| 369 | |
| 370 | Set<String> specs = new HashSet<String>(); |
| 371 | List<MethodData> methodTable = new ArrayList<MethodData>(); |
| 372 | List<Method> refs = new ArrayList<Method>(); |
| 373 | for (Class c: interfaces) { |
| 374 | avian.VMMethod[] ivtable = SystemClassLoader.vmClass(c).virtualTable; |
| 375 | if (ivtable != null) { |
| 376 | for (avian.VMMethod m: ivtable) { |
| 377 | String spec = Classes.toString(m.name) + Classes.toString(m.spec); |
| 378 | if (specs.contains(spec)) { |
| 379 | continue; |
| 380 | } |
| 381 | methodTable.add(new MethodData |
| 382 | (Modifier.PUBLIC, |
| 383 | ConstantPool.addUtf8(pool, Classes.toString(m.name)), |
| 384 | ConstantPool.addUtf8(pool, Classes.toString(m.spec)), |
| 385 | makeInvokeCode(pool, name, m.spec, m.parameterCount, |
| 386 | m.parameterFootprint, methodTable.size()))); |
| 387 | refs.add(Classes.makeMethod(m)); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | methodTable.add(new MethodData |
| 393 | (Modifier.PUBLIC, |
| 394 | ConstantPool.addUtf8(pool, "<init>"), |
| 395 | ConstantPool.addUtf8 |
| 396 | (pool, "(Ljava/lang/reflect/InvocationHandler;)V"), |
| 397 | makeConstructorCode(pool))); |
| 398 | |
| 399 | int nameIndex = ConstantPool.addClass(pool, name); |
| 400 | int superIndex = ConstantPool.addClass(pool, "java/lang/reflect/Proxy"); |
| 401 | |
| 402 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 403 | Assembler.writeClass |
| 404 | (out, pool, nameIndex, superIndex, interfaceIndexes, |
| 405 | methodTable.toArray(new MethodData[methodTable.size()])); |
| 406 | |
| 407 | byte[] classData = out.toByteArray(); |
| 408 | Class result = avian.SystemClassLoader.getClass |
| 409 | (avian.Classes.defineVMClass(loader, classData, 0, classData.length)); |
| 410 | methodRefsMap.put(result, refs.toArray(new Method[refs.size()])); |
| 411 | return result; |
| 412 | } |
| 413 | |
| 414 | public static Object newProxyInstance(ClassLoader loader, |
no test coverage detected