1 26 27 package org.objectweb.fractal.rmi.stub; 28 29 import org.objectweb.fractal.api.Interface; 30 import org.objectweb.fractal.api.control.BindingController; 31 32 import org.objectweb.asm.ClassVisitor; 33 import org.objectweb.asm.ClassWriter; 34 import org.objectweb.asm.CodeVisitor; 35 import org.objectweb.asm.Constants; 36 import org.objectweb.asm.Label; 37 import org.objectweb.asm.Type; 38 39 import org.objectweb.jonathan.apis.binding.ExportException; 40 import org.objectweb.jonathan.apis.binding.Identifier; 41 import org.objectweb.jonathan.apis.kernel.Context; 42 import org.objectweb.jonathan.apis.kernel.JonathanException; 43 import org.objectweb.jonathan.apis.presentation.MarshallerFactory; 44 import org.objectweb.jonathan.apis.protocols.RequestSession; 45 import org.objectweb.jonathan.apis.protocols.SessionIdentifier; 46 import org.objectweb.jonathan.apis.stub_factories.StubFactory; 47 48 import org.objectweb.util.monolog.api.BasicLevel; 49 import org.objectweb.util.monolog.api.Logger; 50 import org.objectweb.util.monolog.api.LoggerFactory; 51 52 import java.lang.reflect.Method ; 53 import java.util.HashMap ; 54 55 69 70 public class RmiStubFactory 71 implements Constants, StubFactory, SkeletonFactory, BindingController 72 { 73 74 77 78 private final static HashMap LOADERS = new HashMap (); 79 80 83 84 protected MarshallerFactory marshallerFactory; 85 86 89 90 protected LoggerFactory loggerFactory; 91 92 95 96 protected Logger logger; 97 98 101 102 public RmiStubFactory () { 103 } 104 105 109 public String [] listFc () { 110 return new String [] { "marshaller-factory", "logger-factory" }; 111 } 112 113 public Object lookupFc (final String clientItfName) { 114 if (clientItfName.equals("marshaller-factory")) { 115 return marshallerFactory; 116 } else if (clientItfName.equals("logger-factory")) { 117 return loggerFactory; 118 } 119 return null; 120 } 121 122 public void bindFc (final String clientItfName, final Object serverItf) { 123 if (clientItfName.equals("marshaller-factory")) { 124 marshallerFactory = (MarshallerFactory)serverItf; 125 } else if (clientItfName.equals("logger-factory")) { 126 loggerFactory = (LoggerFactory)serverItf; 127 logger = loggerFactory.getLogger(getClass().getName()); 128 } 129 } 130 131 public void unbindFc (final String clientItfName) { 132 if (clientItfName.equals("marshaller-factory")) { 133 marshallerFactory = null; 134 } else if (clientItfName.equals("logger-factory")) { 135 loggerFactory = null; 136 logger = null; 137 } 138 } 139 140 144 165 166 public Object newStub ( 167 final SessionIdentifier sessionId, 168 final Identifier[] ids, 169 final Context hints) throws JonathanException 170 { 171 try { 172 String implClassName = (String )hints.getValue("interface_type", (char)0); 173 Class implClass = 174 Thread.currentThread().getContextClassLoader().loadClass(implClassName); 175 Class stubClass = 176 getLoader(implClass).loadClass(getStubClassName(implClass.getName())); 177 if (ids.length != 1) { 178 throw new JonathanException(); 179 } 180 Stub stub = (Stub)stubClass.newInstance(); 181 stub.id = ids[0]; 182 stub.sessionId = sessionId; 183 stub.marshallerFactory = marshallerFactory; 184 if (logger != null && logger.isLoggable(BasicLevel.INFO)) { 185 logger.log(BasicLevel.INFO, "Stub created for id " + ids[0]); 186 } 187 return stub; 188 } catch (Exception e) { 189 throw new JonathanException(e); 190 } 191 } 192 193 197 public RequestSession newSkeleton (final Object target) 198 throws JonathanException 199 { 200 try { 201 if (!(target instanceof Interface)) { 202 throw new Exception ("target object must implement Interface"); 203 } 204 Class implClass = target.getClass(); 205 Class [] itfs = implClass.getInterfaces(); 206 if (itfs.length == 0) { 207 throw new Exception ("target object must implement an interface"); 208 } 209 Class skelClass = 210 getLoader(implClass).loadClass(getSkelClassName(itfs[0].getName())); 211 Skeleton skel = (Skeleton)skelClass.newInstance(); 212 skel.target = target; 213 if (logger != null && logger.isLoggable(BasicLevel.INFO)) { 214 logger.log(BasicLevel.INFO, "Skeleton created for target " + target); 215 } 216 return skel; 217 } catch (Exception e) { 218 throw new ExportException(e); 219 } 220 } 221 222 226 235 236 private Loader getLoader (final Class context) { 237 ClassLoader parent = context.getClassLoader(); 238 Loader instance = (Loader)LOADERS.get(parent); 239 if (instance == null) { 240 instance = new Loader(parent); 241 LOADERS.put(parent, instance); 242 } 243 return instance; 244 } 245 246 249 250 class Loader extends ClassLoader { 251 252 257 258 public Loader (final ClassLoader parent) { 259 super(parent); 260 } 261 262 276 277 protected Class findClass (final String name) 278 throws ClassNotFoundException 279 { 280 if (isStubClassName(name)) { 281 Class itf = loadClass(resolveStubClassName(name)); 282 ClassWriter cw = new ClassWriter(true); 283 generateStubClass(cw, itf); 284 byte[] b = cw.toByteArray(); 285 if (logger != null && logger.isLoggable(BasicLevel.INFO)) { 286 logger.log(BasicLevel.INFO, "Stub class generated: " + name); 287 } 288 296 return defineClass(name, b, 0, b.length); 297 } else if (isSkelClassName(name)) { 298 Class itf = loadClass(resolveSkelClassName(name)); 299 ClassWriter cw = new ClassWriter(true); 300 generateSkeletonClass(cw, itf); 301 byte[] b = cw.toByteArray(); 302 if (logger != null && logger.isLoggable(BasicLevel.INFO)) { 303 logger.log(BasicLevel.INFO, "Skeleton class generated: " + name); 304 } 305 313 return defineClass(name, b, 0, b.length); 314 } else { 315 throw new ClassNotFoundException (name); 316 } 317 } 318 } 319 320 324 332 333 protected void generateStubClass (final ClassVisitor cv, final Class itf) { 334 int access = ACC_PUBLIC; 335 String name = getStubClassName(itf.getName()).replace('.', '/'); 336 String superClass = "org/objectweb/fractal/rmi/stub/Stub"; 337 String [] itfs = new String [] { Type.getInternalName(itf) }; 338 cv.visit(V1_1, access, name, superClass, itfs, null); 339 generateConstructor(cv, superClass); 340 Method [] meths = itf.getMethods(); 341 sort(meths); 342 for (int i = 0; i < meths.length; ++i) { 343 Method meth = meths[i]; 344 generateStubMethod(cv, name, meth, i); 345 } 346 } 347 348 357 358 protected void generateSkeletonClass (final ClassVisitor cv, final Class itf) { 359 int access = ACC_PUBLIC; 360 String name = getSkelClassName(itf.getName()).replace('.', '/'); 361 String superClass = "org/objectweb/fractal/rmi/stub/Skeleton"; 362 cv.visit(V1_1, access, name, superClass, null, null); 363 generateConstructor(cv, superClass); 364 generateSkeletonMethod(cv, name, itf); 365 } 366 367 374 375 protected void generateConstructor ( 376 final ClassVisitor cv, 377 final String superClass) 378 { 379 CodeVisitor mv = cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 380 mv.visitVarInsn(ALOAD, 0); 382 mv.visitMethodInsn(INVOKESPECIAL, superClass, "<init>", "()V"); 383 mv.visitInsn(RETURN); 384 mv.visitMaxs(1, 1); 385 } 386 387 422 423 protected void generateStubMethod ( 424 final ClassVisitor cv, 425 final String name, 426 final Method m, 427 final int index) 428 { 429 String mName = m.getName(); 431 String mDesc = Type.getMethodDescriptor(m); 432 Class [] params = m.getParameterTypes(); 433 int locals = 1; 434 for (int i = 0; i < params.length; ++i) { 435 locals += getSize(params[i]); 436 } 437 Class result = m.getReturnType(); 438 Class [] exceptions = m.getExceptionTypes(); 439 String [] excepts = new String [exceptions.length]; 440 for (int i = 0; i < exceptions.length; ++i) { 441 excepts[i] = Type.getInternalName(exceptions[i]); 442 } 443 CodeVisitor mv = cv.visitMethod(ACC_PUBLIC, mName, mDesc, excepts, null); 444 445 Label beginL = new Label(); 446 Label endL = new Label(); 447 448 mv.visitLabel(beginL); 449 mv.visitVarInsn(ALOAD, 0); 451 mv.visitMethodInsn( 452 INVOKEVIRTUAL, 453 name, 454 "request", 455 "()Lorg/objectweb/jonathan/apis/presentation/Marshaller;"); 456 mv.visitVarInsn(ASTORE, locals); 457 458 mv.visitVarInsn(ALOAD, 0); 460 mv.visitVarInsn(ALOAD, locals); 461 mv.visitMethodInsn( 462 INVOKEVIRTUAL, 463 name, 464 "prepareInvocation", 465 "(Lorg/objectweb/jonathan/apis/presentation/Marshaller;)Lorg/objectweb/jonathan/apis/protocols/ReplyInterface;"); 466 mv.visitVarInsn(ASTORE, locals + 1); 467 468 mv.visitVarInsn(ALOAD, locals); 470 mv.visitIntInsn(SIPUSH, index); 471 mv.visitMethodInsn( 472 INVOKEINTERFACE, 473 "org/objectweb/jonathan/apis/presentation/Marshaller", 474 "writeInt", 475 "(I)V"); 476 477 int offset = 1; 479 for (int i = 0; i < params.length; ++i) { 480 mv.visitVarInsn(ALOAD, locals); 481 if (params[i].isPrimitive()) { 482 mv.visitVarInsn(ILOAD + getOpcodeOffset(params[i]), offset); 483 mv.visitMethodInsn( 484 INVOKEINTERFACE, 485 "org/objectweb/jonathan/apis/presentation/Marshaller", 486 "write" + getMarshallerMethod(params[i]), 487 "(" + Type.getDescriptor(params[i]) + ")V"); 488 } else { 489 if (isClassParameter(m, i)) { 490 mv.visitVarInsn(ALOAD, 0); 491 mv.visitVarInsn(ILOAD + getOpcodeOffset(params[i]), offset); 492 mv.visitMethodInsn( 493 INVOKEVIRTUAL, 494 "org/objectweb/fractal/rmi/stub/Stub", 495 "replaceClassName", 496 "(Ljava/lang/Object;)Ljava/lang/Object;"); 497 } else { 498 mv.visitVarInsn(ILOAD + getOpcodeOffset(params[i]), offset); 499 } 500 mv.visitMethodInsn( 501 INVOKEINTERFACE, 502 "org/objectweb/jonathan/apis/presentation/Marshaller", 503 "writeValue", 504 "(Ljava/lang/Object;)V"); 505 } 506 offset += getSize(params[i]); 507 } 508 509 mv.visitVarInsn(ALOAD, 0); 511 mv.visitVarInsn(ALOAD, locals); 512 mv.visitMethodInsn( 513 INVOKEVIRTUAL, 514 name, 515 "invoke", 516 "(Lorg/objectweb/jonathan/apis/presentation/Marshaller;)V"); 517 518 mv.visitVarInsn(ALOAD, locals + 1); 520 mv.visitMethodInsn( 521 INVOKEINTERFACE, 522 "org/objectweb/jonathan/apis/protocols/ReplyInterface", 523 "listen", 524 "()Lorg/objectweb/jonathan/apis/presentation/UnMarshaller;"); 525 mv.visitVarInsn(ASTORE, locals + 2); 526 527 if (result != Void.TYPE) { 529 if (result.isPrimitive()) { 530 mv.visitVarInsn(ALOAD, locals + 2); 531 mv.visitMethodInsn( 532 INVOKEINTERFACE, 533 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 534 "read" + getMarshallerMethod(result), 535 "()" + Type.getDescriptor(result)); 536 } else { 537 if (isClassParameter(m, -1)) { 538 mv.visitVarInsn(ALOAD, 0); 539 mv.visitVarInsn(ALOAD, locals + 2); 540 mv.visitMethodInsn( 541 INVOKEINTERFACE, 542 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 543 "readValue", 544 "()Ljava/lang/Object;"); 545 mv.visitMethodInsn( 546 INVOKEVIRTUAL, 547 "org/objectweb/fractal/rmi/stub/Stub", 548 "replaceClassValue", 549 "(Ljava/lang/Object;)Ljava/lang/Object;"); 550 } else { 551 mv.visitVarInsn(ALOAD, locals + 2); 552 mv.visitMethodInsn( 553 INVOKEINTERFACE, 554 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 555 "readValue", 556 "()Ljava/lang/Object;"); 557 } 558 mv.visitTypeInsn(CHECKCAST, Type.getInternalName(result)); 559 } 560 mv.visitVarInsn(ISTORE + getOpcodeOffset(result), locals + 3); 561 } 562 563 mv.visitVarInsn(ALOAD, locals + 2); 565 mv.visitMethodInsn( 566 INVOKEINTERFACE, 567 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 568 "close", 569 "()V"); 570 571 if (result != Void.TYPE) { 573 mv.visitVarInsn(ILOAD + getOpcodeOffset(result), locals + 3); 574 mv.visitInsn(IRETURN + getOpcodeOffset(result)); 575 } else { 576 mv.visitInsn(RETURN); 577 } 578 mv.visitLabel(endL); 579 580 mv.visitVarInsn(ASTORE, locals); 581 582 mv.visitVarInsn(ALOAD, 0); 584 mv.visitVarInsn(ALOAD, locals); 585 mv.visitMethodInsn( 586 INVOKEVIRTUAL, 587 name, 588 "handleException", 589 "(Ljava/lang/Exception;)Ljava/lang/Exception;"); 590 mv.visitVarInsn(ASTORE, locals); 591 592 for (int i = 0; i < exceptions.length; ++i) { 594 String type = Type.getInternalName(exceptions[i]); 595 mv.visitVarInsn(ALOAD, locals); 596 mv.visitTypeInsn(INSTANCEOF, type); 597 Label next = new Label(); 598 mv.visitJumpInsn(IFEQ, next); 599 mv.visitVarInsn(ALOAD, locals); 600 mv.visitTypeInsn(CHECKCAST, type); 601 mv.visitInsn(ATHROW); 602 mv.visitLabel(next); 603 } 604 605 mv.visitVarInsn(ALOAD, locals); 607 mv.visitTypeInsn(INSTANCEOF, "java/lang/RuntimeException"); 608 Label next = new Label(); 609 mv.visitJumpInsn(IFEQ, next); 610 mv.visitVarInsn(ALOAD, locals); 611 mv.visitTypeInsn(CHECKCAST, "java/lang/RuntimeException"); 612 mv.visitInsn(ATHROW); 613 mv.visitLabel(next); 614 615 mv.visitTypeInsn(NEW, "org/objectweb/fractal/rmi/RemoteException"); 617 mv.visitInsn(DUP); 618 mv.visitLdcInsn("server side exception"); 619 mv.visitVarInsn(ALOAD, locals); 620 mv.visitMethodInsn( 621 INVOKESPECIAL, 622 "org/objectweb/fractal/rmi/RemoteException", 623 "<init>", 624 "(Ljava/lang/String;Ljava/lang/Exception;)V"); 625 mv.visitInsn(ATHROW); 626 627 mv.visitTryCatchBlock(beginL, endL, endL, "java/lang/Exception"); 629 mv.visitMaxs(0, 0); 630 } 631 632 668 669 protected void generateSkeletonMethod ( 670 final ClassVisitor cv, 671 final String name, 672 final Class itf) 673 { 674 CodeVisitor mv = cv.visitMethod( 675 ACC_PUBLIC, 676 "send", 677 "(Lorg/objectweb/jonathan/apis/presentation/UnMarshaller;Lorg/objectweb/jonathan/apis/protocols/ReplySession;)V", 678 new String [] { "org/objectweb/jonathan/apis/kernel/JonathanException" }, 679 null); 680 681 Label beginL = new Label(); 682 Label endL = new Label(); 683 Label defaultL = new Label(); 684 685 mv.visitLabel(beginL); 687 mv.visitVarInsn(ALOAD, 1); 688 mv.visitMethodInsn( 689 INVOKEINTERFACE, 690 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 691 "readInt", 692 "()I"); 693 mv.visitVarInsn(ISTORE, 3); 694 695 Method [] meths = itf.getMethods(); 697 sort(meths); 698 Label[] cases = new Label[meths.length]; 699 for (int i = 0; i < cases.length; ++i) { 700 cases[i] = new Label(); 701 } 702 if (meths.length > 0) { 703 mv.visitVarInsn(ILOAD, 3); 704 mv.visitTableSwitchInsn(0, meths.length - 1, defaultL, cases); 705 } 706 707 for (int i = 0; i < meths.length; ++i) { 709 Method m = meths[i]; 710 String mName = m.getName(); 711 String mDesc = Type.getMethodDescriptor(m); 712 Class [] params = m.getParameterTypes(); 713 Class result = m.getReturnType(); 714 715 mv.visitLabel(cases[i]); 716 717 mv.visitVarInsn(ALOAD, 0); 719 mv.visitFieldInsn(GETFIELD, name, "target", "Ljava/lang/Object;"); 720 mv.visitTypeInsn(CHECKCAST, Type.getInternalName(itf)); 721 722 for (int j = 0; j < params.length; ++j) { 724 if (params[j].isPrimitive()) { 725 mv.visitVarInsn(ALOAD, 1); 726 mv.visitMethodInsn( 727 INVOKEINTERFACE, 728 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 729 "read" + getMarshallerMethod(params[j]), 730 "()" + Type.getDescriptor(params[j])); 731 } else { 732 if (isClassParameter(m, j)) { 733 mv.visitVarInsn(ALOAD, 0); 734 mv.visitVarInsn(ALOAD, 1); 735 mv.visitMethodInsn( 736 INVOKEINTERFACE, 737 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 738 "readValue", 739 "()Ljava/lang/Object;"); 740 mv.visitMethodInsn( 741 INVOKEVIRTUAL, 742 "org/objectweb/fractal/rmi/stub/Skeleton", 743 "replaceClassValue", 744 "(Ljava/lang/Object;)Ljava/lang/Object;"); 745 } else { 746 mv.visitVarInsn(ALOAD, 1); 747 mv.visitMethodInsn( 748 INVOKEINTERFACE, 749 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 750 "readValue", 751 "()Ljava/lang/Object;"); 752 } 753 mv.visitTypeInsn(CHECKCAST, Type.getInternalName(params[j])); 754 } 755 } 756 757 mv.visitVarInsn(ALOAD, 1); 759 mv.visitMethodInsn( 760 INVOKEINTERFACE, 761 "org/objectweb/jonathan/apis/presentation/UnMarshaller", 762 "close", 763 "()V"); 764 765 mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(itf), mName, mDesc); 767 if (result != Void.TYPE) { 768 mv.visitVarInsn(ISTORE + getOpcodeOffset(result), 5); 769 } 770 771 mv.visitVarInsn(ALOAD, 2); 773 mv.visitMethodInsn( 774 INVOKEINTERFACE, 775 "org/objectweb/jonathan/apis/protocols/ReplySession", 776 "prepareReply", 777 "()Lorg/objectweb/jonathan/apis/presentation/Marshaller;"); 778 mv.visitVarInsn(ASTORE, 4); 779 780 if (result != Void.TYPE) { 782 mv.visitVarInsn(ALOAD, 4); 783 if (result.isPrimitive()) { 784 mv.visitVarInsn(ILOAD + getOpcodeOffset(result), 5); 785 mv.visitMethodInsn( 786 INVOKEINTERFACE, 787 "org/objectweb/jonathan/apis/presentation/Marshaller", 788 "write" + getMarshallerMethod(result), 789 "(" + Type.getDescriptor(result)+ ")V"); 790 } else { 791 if (isClassParameter(m, -1)) { 792 mv.visitVarInsn(ALOAD, 0); 793 mv.visitVarInsn(ILOAD + getOpcodeOffset(result), 5); 794 mv.visitMethodInsn( 795 INVOKEVIRTUAL, 796 "org/objectweb/fractal/rmi/stub/Skeleton", 797 "replaceClassName", 798 "(Ljava/lang/Object;)Ljava/lang/Object;"); 799 } else { 800 mv.visitVarInsn(ILOAD + getOpcodeOffset(result), 5); 801 } 802 mv.visitMethodInsn( 803 INVOKEINTERFACE, 804 "org/objectweb/jonathan/apis/presentation/Marshaller", 805 "writeValue", 806 "(Ljava/lang/Object;)V"); 807 } 808 } 809 810 mv.visitVarInsn(ALOAD, 2); 812 mv.visitVarInsn(ALOAD, 4); 813 mv.visitMethodInsn( 814 INVOKEINTERFACE, 815 "org/objectweb/jonathan/apis/protocols/ReplySession", 816 "send", 817 "(Lorg/objectweb/jonathan/apis/presentation/Marshaller;)V"); 818 819 mv.visitVarInsn(ALOAD, 2); 821 mv.visitMethodInsn( 822 INVOKEINTERFACE, 823 "org/objectweb/jonathan/apis/protocols/ReplySession", 824 "close", 825 "()V"); 826 827 mv.visitInsn(RETURN); 829 } 830 831 mv.visitLabel(defaultL); 835 mv.visitVarInsn(ALOAD, 0); 836 mv.visitVarInsn(ALOAD, 1); 837 mv.visitVarInsn(ALOAD, 2); 838 mv.visitVarInsn(ILOAD, 3); 839 mv.visitMethodInsn( 840 INVOKEVIRTUAL, 841 name, 842 "handleInterfaceMethods", 843 "(Lorg/objectweb/jonathan/apis/presentation/UnMarshaller;Lorg/objectweb/jonathan/apis/protocols/ReplySession;I)V"); 844 mv.visitInsn(RETURN); 845 846 mv.visitLabel(endL); 848 mv.visitVarInsn(ASTORE, 3); 849 mv.visitVarInsn(ALOAD, 0); 850 mv.visitVarInsn(ALOAD, 3); 851 mv.visitVarInsn(ALOAD, 2); 852 mv.visitMethodInsn( 853 INVOKEVIRTUAL, 854 name, 855 "handleException", 856 "(Ljava/lang/Exception;Lorg/objectweb/jonathan/apis/protocols/ReplySession;)V"); 857 mv.visitInsn(RETURN); 858 859 mv.visitTryCatchBlock(beginL, endL, endL, "java/lang/Exception"); 861 mv.visitMaxs(0, 0); 862 } 863 864 883 884 protected boolean isClassParameter (final Method m, final int p) { 885 String name = m.getName(); 886 if (name.equals("getFcContentDesc")) { 887 return p == -1; 888 } else if (name.equals("newFcInstance")) { 889 return p == 2; 890 } else if (name.equals("getFcItfSignature")) { 891 return p == -1; 892 } else if (name.equals("createFcItfType")) { 893 return p == 1; 894 } 895 return false; 896 } 897 898 907 908 protected static void sort (final Method [] methods) { 909 String [] descs = new String [methods.length]; 910 for (int i = 0; i < descs.length; ++i) { 911 descs[i] = methods[i].getName() + Type.getMethodDescriptor(methods[i]); 912 } 913 for (int i = 0; i < descs.length; ++i) { 914 for (int j = i + 1; j < descs.length; ++j) { 915 if (descs[j].compareTo(descs[i]) < 0) { 916 String s = descs[i]; 917 descs[i] = descs[j]; 918 descs[j] = s; 919 Method m = methods[i]; 920 methods[i] = methods[j]; 921 methods[j] = m; 922 } 923 } 924 } 925 } 926 927 935 936 private static String getMarshallerMethod (final Class type) { 937 if (type == Byte.TYPE) { 938 return "Byte"; 939 } else if (type == Integer.TYPE) { 940 return "Int"; 941 } else if (type == Boolean.TYPE) { 942 return "Boolean"; 943 } else if (type == Double.TYPE) { 944 return "Double"; 945 } else if (type == Float.TYPE) { 946 return "Float"; 947 } else if (type == Long.TYPE) { 948 return "Long"; 949 } else if (type == Character.TYPE) { 950 return "Char16"; 951 } else { 952 return "Short"; 953 } 954 } 955 956 967 968 private static int getOpcodeOffset (final Class type) { 969 if (type == Double.TYPE) { 970 return 3; 971 } else if (type == Float.TYPE) { 972 return 2; 973 } else if (type == Long.TYPE) { 974 return 1; 975 } else if (type.isPrimitive()) { 976 return 0; 977 } 978 return 4; 979 } 980 981 988 989 private static int getSize (final Class type) { 990 return (type == Double.TYPE || type == Long.TYPE ? 2 : 1); 991 } 992 993 999 1000 private static String getStubClassName (final String className) { 1001 if (className.startsWith("java.")) { 1002 return "stub." + className + "_JavaStub"; 1003 } else { 1004 return className + "_Stub"; 1005 } 1006 } 1007 1008 1014 1015 private static boolean isStubClassName (final String className) { 1016 return className.endsWith("_JavaStub") || className.endsWith("_Stub"); 1017 } 1018 1019 1025 1026 private static String resolveStubClassName (final String stubClassName) { 1027 if (stubClassName.endsWith("_JavaStub")) { 1028 return stubClassName.substring(5, stubClassName.length() - 9); 1029 } else { 1030 return stubClassName.substring(0, stubClassName.length() - 5); 1031 } 1032 } 1033 1034 1040 1041 private static String getSkelClassName (final String className) { 1042 if (className.startsWith("java.")) { 1043 return "skel." + className + "_JavaSkel"; 1044 } else { 1045 return className + "_Skel"; 1046 } 1047 } 1048 1049 1055 1056 private static boolean isSkelClassName (final String className) { 1057 return className.endsWith("_JavaSkel") || className.endsWith("_Skel"); 1058 } 1059 1060 1066 1067 private static String resolveSkelClassName (final String skelClassName) { 1068 if (skelClassName.endsWith("_JavaSkel")) { 1069 return skelClassName.substring(5, skelClassName.length() - 9); 1070 } else { 1071 return skelClassName.substring(0, skelClassName.length() - 5); 1072 } 1073 } 1074} 1075 | Popular Tags |