(19) United States (12) Patent Application Publication (10) Pub
Total Page:16
File Type:pdf, Size:1020Kb
US 20060190934A1 (19) United States (12) Patent Application Publication (10) Pub. No.: US 2006/0190934 A1 Kielstra et al. (43) Pub. Date: Aug. 24, 2006 (54) METHOD AND APPARATUS FOR INLINING Publication Classi?cation NATIVE FUNCTIONS INTO COMPILED JAVA CODE (51) Int. Cl. G06F 9/45 (2006.01) (52) US. Cl. ............................................................ ..717/148 (75) Inventors: Allan Henry Kielstra, Ajax (CA); Levon Sassoon Stepanian, Toronto (CA); Kevin Alexander Stoodley, (57) ABSTRACT Richmond Hill (CA) A method, apparatus, and computer instructions are pro vided for inlining native functions into compiled Java code. Correspondence Address: A conversion engine is provided by the present invention for IBM CORP (YA) converting the intermediate representation of native func C/O YEE & ASSOCIATES PC tions to the just-in-time (JIT) compiler’s intermediate rep PO. BOX 802333 resentation. With the converted intermediate representation, DALLAS, TX 75380 (US) an inliner recursively inlines the converted JIT compiler’s intermediate representation into the native callsite to remove the need of invoking the native function and subsequent (73) Assignee: International Business Machines Cor native calls made by the function. The inlining process poration, Armonk, NY continues until either a call to an opaque function is encoun tered or until a JIT compiler intermediate representation groWth limits are reached. The inliner also replaces calls to (21) Appl. No.: 11/062,293 most native functions that are non-inlineable or opaque With calls to synthesized native functions that provide access to native libraries containing implementations of the original (22) Filed: Feb. 18, 2005 non-inlineable calls. 100 Patent Application Publication Aug. 24, 2006 Sheet 1 0f 6 US 2006/0190934 A1 100 \ x104 C558" 202 208 204 216 \ \ I \ -/ / HOST/PCI MAIN AUDIO PROCESSOR <i> CACHE/BRIDGE <Z> MEMORY ADAPTER BUS ? 1? < U> 206/ l} U U ii > SCSI HOST LAN EXPQFEION GRAPH'CS é/Lfgég/ BUS ADAPTER ADAPTER INTERFACE ADAPTER ADAPTER / F \ \ \ 212 210 214 218 219 < ' ' > < U > DISK /226 U U 220\ KEYBOARD AND TAPE MOUSE ADAPTER MODEM MEMORY \ 228 CD Rom \ \ ' \230 FIG. 2 222 224 Patent Application Publication Aug. 24, 2006 Sheet 2 0f 6 US 2006/0190934 A1 /3OO 304 \ PLATFORM [302 6 JAVA VIRTUAL SPECIFIC \ MACHINE (JVM) OPERATING ‘ JAVA SYSTEM FIG 3 APPLICATION/APPLET - 402\ CLASS LOAOER SUBSYSTEM HEILLQES 400 ' 410 416 418 420 422 424 \ \ \ / / / MEMORY hg'éiTTk'éEn JAVA PC METHOD HEAP MANAGEMENT STACKS STACKS REGIsTERs AREA RuNTIME DATA AREAS 404/4 ? i} I 406/ EXECUTION ENGINE v NATIvE NATIvE COMPILER INTERPRETER < > METHOD <—METFIOO FIG' 4 INTERFACE LIBRARIES / \ \ 414 412 408 Patent Application Publication Aug. 24, 2006 Sheet 3 0f 6 US 2006/0190934 A1 500 504 502 506 508 \ / / NATIvE CODE INTERNAL a = b + C; NAT'VE 'R CONVERSION JIT IR ENGINE FIG. 5 602\ NATIVE CALLSITE 11”", NATNE IR /606 II \ \ IN ENCOUNTERS v JIT COMPILER / CONVERSION 600 INLINER ENGINE 604 INLINES OUT V ’ V zz” INTERNAL NATIVE CALLSITE' :: \ 610/ ~‘~\\_ JITIR 608 FIG. 6 Patent Application Publication Aug. 24, 2006 Sheet 4 0f 6 US 2006/0190934 A1 704 l l l I 703 NATIVE LIBRARY 1 / CONTAINING I z SYNTHESIZED IMPLEMENTATIONs ' <2 5’3 NATIVE FOR FUNCTIONS ' 6 i FUNCTION A A AND B I B QLLI l E 5 SYNTHESIZED ' 5 <21 NATIVE \705 i <2‘ % FUNCTION B :| “gQ QE SYNTHESIZED O I Z = NATIvE I FUNCTION C NATIvE LIBRARY l \ CONTAINING l 707 IMPLEMENTATION l FOR FUNCTION 0 l | i 706 | LIBRARY MEMORY SPACE 306 \ 812 800 JAVA FUN C TION '/ 810\ 802 SYNTHES'ZED N’ETI'IYIEIIKIZIF?SY NATIvE \ FUNCTION IMPLEMENTATION E z ifiiPFQP/WT'QN.PFFN'QXQZFE READ/WR'TE ( Q 7 // /// / /// // TOX Ez (2'- j////OPAOUE /////////// NATIvE CALL/ /\ 808 E E ~ ' 804 2 / \\ MEMORY FOR \ DATA ITEMX FIG. 8 Patent Application Publication Aug. 24, 2006 Sheet 5 0f 6 US 2006/0190934 A1 @ 900 RUN JIT COMPILER TO / FIG. 9 STANDARD INLINING PHASE 'II A CALL TO NATIVE / 902 FUNCTION IS ENCOUNTERED 904 ' OPAOUE NO FUNCTION CALL? 906 924 ORIGINAL FUNCTION CALL CALLSITE THAT YES FROM JAVA TO NATIVE STARTED INLINING CODE? PROCESS? 918 \ SYNTHESIZE NON-INLINEABLE CONvERT NATIvE IR TO / 908 NATIvE FUNCTION JIT COMPILER's IR REPLACE FUNCTION CALL REPLACE NATIvE FUNCTION WITH CALL TO SYNTHESIZED CALL WITH ACTLIAL \ 910 NATIvE FUNCTION IIvIPLEIvIENTATION / I 920 MATERIALIZED JNIEnv POINTER Is PASSED T0 INLINED CODE \ 912 JIT CDMPILER YES 922 GROWTH LIMIT 7V / REACHED'? RESUME JIT COMPILER PROCESSING DOES INLINED CODE HAVE ANY MORE @ CALLS? YES Patent Application Publication Aug. 24, 2006 Sheet 6 of 6 US 2006/0190934 A1 class DummyCall \1000 public static native mt dummy(); \ 1002 public static void main(String [] args)\1004 FIG. 1 0A { int x = dummy() + dummy(); } / \ \ } 1006 1008 1010 #include <jni.h> #include "DummyCallh" 1/020 JNIEXPORTJimJNICALL?x??ovumgwrxlcité ggrgmy FIG, 10B { , return100; } Method: (main)_/ 1030 Integer-store into automatic variable [<temporary 1 >] - Integer add 1032 E>o Function-callLoad-address tostatic[<address method DummyCall.dummy()| of class object>] / 1 1;’) Function-call to method DummyCall.dummy()l \ 1034 o Load-address static[<address of class object>] Method: (maln)_/‘ 1040 Integer-store into automatic variable [<temporary 1 >] - integer100 add (NOTE: Function-call eliminated) F] 1 100 (NOTE: Function-call eliminated) Method: (main) integer-store 200into automatic variable [<temporary 1 >] I US 2006/0190934 A1 Aug. 24, 2006 METHOD AND APPARATUS FOR INLINING as a Java application or applet on a Web Server, Where it can NATIVE FUNCTIONS INTO COMPILED JAVA be doWnloaded over a netWork to a user’s machine and CODE executed on a local JVM. [0008] The Java run-time environment is speci?cally CROSS-REFERENCE TO RELATED designed to limit the harm that a Java application can cause APPLICATION to the system that it is running on. This is especially important With the World Wide Web, Where Java applets are [0001] The present invention is related to the co-pending doWnloaded and executed automatically When a user visits application entitled “METHOD AND APPARATUS FOR a Web page that contains Java applets. Normally one Would TRANSFORMING JAVA NATIVE INTERFACE FUNC not Want to execute random programs; they might contain TION CALLS INTO SIMPLER OPERATIONS DURING viruses, or they might even be potentially malicious them JUST-IN-TIME COMPILATION”, Ser. no. , attor selves and not merely carrying unWelcome code uninten ney docket no. CA920050002US1 ?led on tionally. Unless the user speci?cally alloWs it (by setting the appropriate ?ags in the user-interface to the JVM), a Java BACKGROUND OF THE INVENTION applet cannot read or Write to attached storage devices [0002] 1. Technical Field (except perhaps to a speci?c, restricted area), nor can it read or Write to memory locations (except to a speci?c, restricted [0003] The present invention relates to an improved data area). processing system. In particular, the present invention [0009] Not only are Java applets designed for doWnload relates to Java native functions in a data processing system. ing over the network, standard Java libraries also speci? Still more particular, the present invention relates to inlining cally support client-server computing. The Java language Java native function calls in compiled Java code in a data includes provisions for multi-threading and for netWork processing system. communications. Compared to other languages (such as C), [0004] 2. Description of Related Art it is much easier to Write a pair of programs, one executing locally on the user’s computer that is handling the user [0005] Java is an object oriented programming language interaction, and the other executing remotely on a server, and environment focusing on de?ning data as objects and Which is performing potentially more sophisticated and the methods that may be applied to those objects. Java processor-intensive Work. supports only single inheritance, meaning that each class can [0010] While the Java language is designed to be plat inherit from only one other class at any given time. Java also form-independent, and to execute primarily in a secure alloWs for the creation of totally abstract classes knoWn as environment, programmers can extend Java applications interfaces, Which alloW the de?ning of methods that may be through the use of compiled native binary code on the host shared With several classes Without regard for hoW other operating system using C-style calling conventions through classes are handling the methods. Java provides a mecha the Java Native Interface (JNI). In this fashion, a Java nism to distribute softWare and extends the capabilities of a application can have complete access to the host operating Web broWser because programmers can Write an applet once system, including reading and Writing to attached I/O and the applet can be run on any Java enabled machine on devices, memory, etc. Because of this, Java programs can the Web. accomplish tasks that are not normally alloWed via the JVM [0006] The Java virtual machine (JV M) is a virtual com at the cost of being platform-speci?c. HoWever, With a puter component that resides only in memory. The JVM Well-designed architecture, a Java language programmer can alloWs Java programs to be executed on different platforms cleanly isolate the platform-independent portion, and as opposed to only the one platform for Which the code Was present a clean, platform-independent object API to other compiled. Java programs are compiled for the JVM. In this Java components While at the same time accomplishing manner Java is able to support applications for many types platform-speci?c tasks. of data processing systems, Which may contain a variety of [0011] When invoking native function calls in the com central processing units and operating systems architectures. piled Java code through the JNI, overheads are associated. To enable a Java application to execute on different types of For example, Work must be performed at run time in order data processing systems, a compiler typically generates an to prepare the call for invocation.