US 2002/0194243 A1 Sokolov Et Al
Total Page:16
File Type:pdf, Size:1020Kb
US 2002O194243A1 (19) United States (12) Patent Application Publication (10) Pub. No.: US 2002/0194243 A1 Sokolov et al. (43) Pub. Date: Dec. 19, 2002 (54) REDUCED INSTRUCTION SET FOR JAVA (52) U.S. Cl. .............................................................. 709/101 VIRTUAL MACHINES (57) ABSTRACT (75) Inventors: Stepan Sokolov, Fremont, CA (US); Techniques for implementing virtual machine instructions David Wallman, Sunnyvale, CA (US) Suitable for execution in Virtual machines are disclosed. The inventive virtual machine instructions can effectively repre Correspondence Address: Sent the complete Set of operations performed by the con BEYER WEAVER & THOMAS LLP ventional Java Bytecode instruction set. Moreover, the P.O. BOX 778 operations performed by conventional instructions can be BERKELEY, CA 94704-0778 (US) performed by relatively fewer inventive virtual machine Assignee: Sun Microsystems, Inc. instructions. Thus, a more elegant, yet robust, Virtual (73) machine instruction Set can be implemented. This, in turn, allows implementation of relatively simpler interpreters as (21) Appl. No.: 09/819,120 well as allowing alternative uses of the limited 256 (2) (22) Filed: Mar. 27, 2001 Bytecode representation (e.g., a macro representing a set of commands). As a result, the performance of Virtual Publication Classification machines, especially, those operating in Systems with lim ited resources, can be improved by using the inventive (51) Int. Cl. ................................................. G06F 9/00 Virtual machine instructions. 204 2052 1 200 - Byte Byte Byte 108 110 112 (Command) (Parameter) (Parameter) Java Bytecode A Virtual machine Translator instrcution O2 2O6 Vitrual machine 210 Virtual machine instruction Loader 208 internal Repesentation 212 Patent Application Publication Dec. 19, 2002. Sheet 1 of 14 US 2002/0194243 A1 100 102 1. CP-index Constant Pool Execution Stack Top Patent Application Publication Dec. 19, 2002. Sheet 2 of 14 US 2002/0194243 A1 1 250 Y W W V W Y w t W w k A. W BCM s B V V B w w V W w Patent Application Publication Dec. 19, 2002. Sheet 3 of 14 US 2002/0194243 A1 205 204 2 1. 20 O Byte Byte Byte 108 110 112 (Command) (Parameter) (Parameter) Java Bytecode A Virtual machine Translator instrcution 2O6 Vitrual machine Virtual machine 210 instruction Loader 208 internal Repesentation 212 Fig. 2A Patent Application Publication Dec. 19, 2002 Sheet 4 of 14 US 2002/0194243 A1 -300 Command C 31 Patent Application Publication Dec. 19, 2002 Sheet 5 of 14 US 2002/0194243 A1 y 400 PUSH Fig. 4A Patent Application Publication Dec. 19, 2002 Sheet 6 of 14 US 2002/0194243 A1 OP PUSHL ldc2 w Fig. 4C Fig. 4D Patent Application Publication Dec. 19, 2002 Sheet 7 of 14 US 2002/0194243 A1 PUSHB iconst 1 iconst 4 Fig. 4F Patent Application Publication Dec. 19, 2002 Sheet 8 of 14 US 2002/0194243 A1 -500 T Execution Stack 522 Offset 1 524 Offset i(A)--...------------- Patent Application Publication Dec. 19, 2002. Sheet 9 of 14 US 2002/0194243 A1 LOAD LOADL Fig. 5B Fig. 5C Patent Application Publication Dec. 19, 2002. Sheet 10 of 14 US 2002/0194243 A1 T Execution stack 604 Patent Application Publication Dec. 19, 2002 Sheet 11 of 14 US 2002/0194243 A1 1. 620 prowry-aa---------assau---aaaaasser-mour-sroarr Execution Stack 604 Astore 622 ASTORE ASTOREL Patent Application Publication Dec. 19, 2002 Sheet 12 of 14 US 2002/0194243 A1 Fig. 6F Fig. 6H Patent Application Publication Dec. 19, 2002 Sheet 13 of 14 US 2002/0194243 A1 Execution Stack Patent Application Publication Dec. 19, 2002 Sheet 14 of 14 US 2002/0194243 A1 & e D 5 Z. ? g o 55 9. 5 L US 2002/0194243 A1 Dec. 19, 2002 REDUCED INSTRUCTION SET FOR JAVA the Java virtual machine instructions for the methods of a VIRTUAL MACHINES class, the class file format includes a Significant amount of ancillary information that is associated with the class. The CROSS-REFERENCE TO RELATED class file format (as well as the general operation of the Java APPLICATIONS virtual machine) is described in some detail in The Java Virtual Machine Specification by Tim Lindholm and Frank 0001. This application is related to U.S. patent applica Yellin (ISBN 0-201-31006-6), which is hereby incorporated tion Ser. No. (Att.Dkt.No. SUN1P827/P6095), entitled herein by reference. “ENHANCED VIRTUAL MACHINE INSTRUCTIONS", filed on an even date, and hereby incorporated herein by 0009 Conventional virtual machines interpreter decodes reference for all purposes. and executes the Java Bytecode instructions, one instruction at a time during execution, e.g., “at runtime.” To execute a 0002 This application is related to U.S. patent applica Java instruction, typically, Several operations have to been tion Ser. No. 09/703,361 (Att.Dkt.No. SUN1P809/P5500), performed to obtain the information that is necessary to entitled “IMPROVED FRAMEWORKS FOR INVOKING execute the Java instruction. For example, to invoke a METHODS IN VIRTUAL MACHINES", which is hereby method referenced by a Java bytecode, the Virtual machine incorporated herein by reference for all purposes. must perform Several operations to access the Constant Pool 0003. This application is related to U.S. patent applica Simply to identify the information necessary to locate and tion Ser. No. 09/703,356 (Att.Dkt.No. SUN1P810/P5510), access the invoked method. entitled “IMPROVED METHODS AND APPARTUS FOR 0010. As described in The Java Virtual Machine Speci NUMERIC CONSTANT VALUE INLINING IN VIRTUAL fication, one of the Structures of a Standard class file is MACHINES", which is hereby incorporated herein by ref known as the “Constant Pool.” The Constant Pool is a data erence for all purposes. Structure that has several uses. One of the uses of the 0004. This application is related to U.S. patent applica Constant Pool that is relevant to the present invention is that tion Ser. No. 09/703,449 (Att.Dkt.No. SUN1P814/P5417), the Constant Pool contains the information that is needed to entitled “IMPROVED FRAMEWORKS FOR LOADING resolve various Java Instructions. To illustrate, FIG. 1 AND EXECUTION OF OBJECT-BASED PROGRAMS", depicts a conventional computing environment 100 includ which is hereby incorporated herein by reference for all ing a stream of Java Bytecodes 102, a constant pool 104 and purposes. an execution stack 106. The stream of Java Bytecodes 102 represents a Series of bytes in a stream where one or more BACKGROUND OF THE INVENTION bytes can represent a Java Bytecode instruction. For example, a byte 108 can represent a Ldc (load constant on 0005 The present invention relates generally to object the execution stack) Bytecode command 108. Accordingly, based high level programming environments, and more the bytes 110 and 112 represent the parameters for the Ldc particularly, to virtual machine instruction Sets Suitable for Bytecode comand 108. In this case, these bytes respectively execution in Virtual machines operating in portable, platform represent a CP-IndexA 100 and CP-lindexB 112 that collec independent programming environments tively represent the indeX to appropriate constant value in 0006 Recently, the JavaTM programming environment the constant pool 104. For example, bytes C1, C2, C3 and has become quite popular. The Java" programming lan C4 of the constant pool 104 can collectively represent the guage is a language that is designed to be portable enough appropriate 4 byte (one word) constant C that is to loaded to to be executed on a wide range of computers ranging from the top of the execution stack 106. It should be noted that Small devices (e.g., pagers, cell phones and Smart cards) up Ldc Bytecode command 108 and its parameters represented to Supercomputers. Computer programs written in the Java by bytes 110 and 112 are collectively referred to herein as a programming language (and other languages) may be com Java Bytecode instruction. piled into Java Bytecode instructions that are suitable for 0011. In order to execute the Java Bytecode Ldc Instruc execution by a Java virtual machine implementation. tion 108, at run time, an index to the Constant Pool 104 is 0007. The Java virtual machine is commonly imple constructed from the CP-IndexA and CP-IndexA. Once an mented in Software by means of an interpreter for the Java index to the Constant Pool has been determined, the appro Virtual machine instruction Set but, in general, may be priate Structures in the Constant Pool have to be accessed So Software, hardware, or both. A particular Java Virtual that the appropriate constant value can be determined. machine implementation and corresponding Support librar Accordingly, the Java Bytecode Ldc instruction can be ies, together constitute a Java" runtime environment. executed only after performing Several operations at run time. AS can be appreciated from the example above, the 0008 Computer programs in the Java programming lan execution of a relatively simple instruction Such as loading guage are arranged in one or more classes or interfaces a constant value can take a Significant amount of run time. (referred to herein jointly as classes or class files). Such programs are generally platform, i.e., hardware and operat Hence, this conventional technique is an inefficient approach ing System, independent. AS Such, these computer programs that may result in Significantly longer execution times. may be executed without modification, on any computer that 0012 Another problem is that the conventional Java is able to run an implementation of the JavaTM runtime Bytecode instruction Set has more than 220 instructions. environment. A class written in the Java programming Moreover, there is a Significant amount of redundancy language is compiled to a particular binary format called the between Some instructions in the conventional Java Byte “class file format” that includes Java virtual machine code instruction Set. For example, there are different Java instructions for the methods of a single class.