[go: up one dir, main page]

CN1251076C - Acceleration of method call in virtual machine - Google Patents

Acceleration of method call in virtual machine Download PDF

Info

Publication number
CN1251076C
CN1251076C CNB031374654A CN03137465A CN1251076C CN 1251076 C CN1251076 C CN 1251076C CN B031374654 A CNB031374654 A CN B031374654A CN 03137465 A CN03137465 A CN 03137465A CN 1251076 C CN1251076 C CN 1251076C
Authority
CN
China
Prior art keywords
hash
class
hash table
program
virtual machine
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CNB031374654A
Other languages
Chinese (zh)
Other versions
CN1495608A (en
Inventor
莫拉德·德巴比
那蒂亚·塔乌比
萨米·佐阿
莫拉德·伊里欧
拉米亚·凯塔里
哈姆蒂·雅夏欧
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Panasonic Holdings Corp
Original Assignee
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Matsushita Electric Industrial Co Ltd filed Critical Matsushita Electric Industrial Co Ltd
Publication of CN1495608A publication Critical patent/CN1495608A/en
Application granted granted Critical
Publication of CN1251076C publication Critical patent/CN1251076C/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

一种基于计算机平台的系统通过提高方法调用的速度来提高代码执行速度。一虚拟机包括一装载器、一解释器和一线程管理器。装载器利用方法特征构建一散列表,解释器搜索该散列表以找到各方法的位置。解释器利用有一指向一接收器的指针的方法调用高速缓冲存储器来提高代码运行速度。线程管理器用一深度水平来提高锁定状态转换的速度。

Figure 03137465

A system based on a computer platform to increase the speed of code execution by increasing the speed of method calls. A virtual machine includes a loader, an interpreter and a thread manager. The loader builds a hash table using method characteristics, which the interpreter searches to find the location of each method. The interpreter utilizes a method call cache with a pointer to a receiver to increase code execution speed. The thread manager uses a level of depth to increase the speed of lock state transitions.

Figure 03137465

Description

用来提高至少一个程序执行速度的基于计算机平台的系统及方法Computer platform-based systems and methods for increasing execution speed of at least one program

本申请要求享有2002年8月22日提出的第60/405,266号美国临时申请的利益。以上申请所披露的内容在此引用以作参考。This application claims the benefit of US Provisional Application No. 60/405,266, filed August 22,2002. The disclosures of the above applications are incorporated herein by reference.

技术领域technical field

本发明涉及提高代码执行速度,尤其涉及在象JAVA这样的面向对象的环境中运行的虚拟机中方法调用机制(mechanism)的加速。The present invention relates to increasing the speed of code execution, and more particularly to the acceleration of the method invocation mechanism in a virtual machine running in an object-oriented environment like JAVA.

背景技术Background technique

面向对象的语言支持继承性和多态性以允许开发灵活且可重复使用的软件。一种典型的面向对象的程序包括一组类。这些类中的每一个都可以定义一组数据成员。另外,每一个类可以包括一组方法,这些方法对该组数据成员起作用。Object-oriented languages support inheritance and polymorphism to allow the development of flexible and reusable software. A typical object-oriented program consists of a set of classes. Each of these classes can define a set of data members. Additionally, each class can include a set of methods that act on that set of data members.

继承性使一个类能够“继承”或派生(derive)一个父类的各个能力(capability)。因此,由于有继承性,所以一个给定的方法可以为父类和子类所共有。当调用这样一个共有方法时,执行机制必须确定所调用的方法是否正在对父类或子类的对象起作用。用方法特征区分对各对象起作用的方法,这些特征通常由以下部分组成:方法名;参数数量、参数类型和参数顺序(order);对象的相关类。Inheritance enables a class to "inherit" or derive the capabilities of a parent class. Thus, because of inheritance, a given method can be shared by both parent and child classes. When calling such a public method, the execution mechanism must determine whether the called method is acting on an object of a superclass or a subclass. Use method characteristics to distinguish methods that work on each object, and these characteristics usually consist of the following parts: method name; parameter number, parameter type, and parameter order (order); and the related class of the object.

给定对象的类型通常会在运行时间得以确定。将这种在运行时间确定对象类型的方法称为“动态连接”。在这方面,对所要执行的适当方法的选择是基于一查找机制(lookup mechanism),这意味要在调用之后执行的实际方法是基于该方法接收器的类型、类层次性和方法继承性或重载模式(overloadingschema)而动态确定的。下面描述一种典型的查找机制。The type of a given object is usually determined at runtime. This method of determining the type of an object at runtime is called "dynamic linking". In this regard, the selection of the appropriate method to execute is based on a lookup mechanism, which means that the actual method to execute after an invocation is based on the method receiver's type, class hierarchy, and method inheritance or re- Dynamically determined by the overloading schema. A typical lookup mechanism is described below.

这种查找机制确定出现调用时所要执行的实际方法。如果一个类执行了与所调用方法具有相同特征的方法,那么执行找到的方法。否则,以递归的方式检查父类,直到找到搜索的方法为止。如果没有找到任何一个方法,那么就发出一个错误信号(MsgNotUnderstood)。就执行时间和其他资源而言,这种操作发生得过于频繁且花费昂贵。因此,需要提高查找机制的速度。This lookup mechanism determines the actual method to execute when a call occurs. If a class executes a method with the same characteristics as the called method, then the found method is executed. Otherwise, parent classes are checked recursively until the searched method is found. If none of the methods are found, an error signal (MsgNotUnderstood) is emitted. This happens too often and is expensive in terms of execution time and other resources. Therefore, there is a need to increase the speed of the lookup mechanism.

静态技术对该查找的一部分进行预先计算,而动态技术采用前面查找的结果的一个高速缓冲存储器,这样避免了其他查找。最重要的动态连接算法称为分派表搜索(Dispatch Table Search)(DTS)。就空间成本而言,这种DTS是一种很好的方法,但是,与DTS有关的搜索负担使得该机制过于缓慢。需要减少与DTS有关的开销。现已提出许多技术来减少与DTS有关的开销:对查找的一部分进行预先计算的静态技术和高速缓存前面查找的结果的动态技术,这样避免了其他查找。下面描述上述技术。Static techniques precompute part of the lookup, while dynamic techniques use a cache of results from previous lookups, thus avoiding additional lookups. The most important dynamic join algorithm is called Dispatch Table Search (DTS). This DTS is a good approach in terms of space cost, however, the search burden associated with DTS makes this mechanism too slow. There is a need to reduce the overhead associated with DTS. A number of techniques have been proposed to reduce the overhead associated with DTS: static techniques that precompute part of a lookup, and dynamic techniques that cache the results of previous lookups, thus avoiding additional lookups. The above techniques are described below.

一种称为选择表索引(selector table Indexing)(STI)的技术是用来加速查找机制的静态方法。下面将简述这种STI技术。假定有一C类和S选择器的类层次结构,建立起一个C*S项的二维阵列。在每一个轴上为各个类和选择器赋予连续的号,通过预先计算每一个类和选择器的查找来填充该阵列。一个阵列项含相应方法或一个错误处理程序(error routine)的一个基准值。为一个完整的系统计算这些表。A technique called selector table Indexing (STI) is a static method used to speed up the lookup mechanism. This STI technique will be briefly described below. Assuming a class hierarchy of C classes and S selectors, a two-dimensional array of C*S items is built. Assigning consecutive numbers to classes and selectors on each axis, the array is populated by precomputing lookups for each class and selector. An array item containing a reference value for the corresponding method or an error routine. Calculate these tables for a complete system.

STI技术传送快速和恒定的时间查找。但是,STI的主要缺点在于,对于一个具有有限计算资源的普通系统例如一个嵌入式系统来说,对于空间的需求是巨大的。现已提出许多分派表压缩技术以减小所需空间的间接开销,象选择器着色(selector coloring),行位移技术等等。但是,这些技术的实施给象嵌入式系统这样的有限计算资源环境带来了不必要的负担。这种技术的另一个缺点是,编译代码对类层次结构中的变化非常敏感。通过STI建立的二维阵列固定于编译时间。但是对于象JAVA这样的语言来说,这组类能够动态变化。STI无法控制这一情形,因为它不能动态改变该阵列。STI technology delivers fast and constant time lookups. However, the main disadvantage of STI is that for an ordinary system with limited computing resources such as an embedded system, the space requirement is huge. Many dispatch table compression techniques have been proposed to reduce the overhead of required space, such as selector coloring (selector coloring), row displacement techniques, and so on. However, the implementation of these technologies places an unnecessary burden on limited computing resource environments such as embedded systems. Another disadvantage of this technique is that the compiled code is very sensitive to changes in the class hierarchy. Two-dimensional arrays created by STI are fixed at compile time. But for languages like Java, this set of classes can change dynamically. STI has no control over this situation because it cannot dynamically change the array.

同步技术改善了用来执行多线程应用的线程管理器功能。这种用于传统嵌入式JAVA虚拟机中的同步技术(尤其是那些基于千字节虚拟机的技术)与四状态中的一个对象状态相关联:(1)未锁定,(2)简单锁定,(3)扩展锁定(extend locked),或者是(4)与一个监视程序(monitor)有关的状态。因此,需要同步技术不与任何特定的锁定状态相关联。Synchronization techniques improve the functionality of thread managers used to execute multithreaded applications. This synchronization technique used in traditional embedded Java virtual machines (especially those based on Kilobyte virtual machines) is associated with an object state in one of four states: (1) unlocked, (2) simply locked, (3) extend locked, or (4) a state associated with a monitor. Therefore, it is required that the synchronization technique is not associated with any particular locking state.

所以,就计算资源处理/执行时间、存储器和方法搜索或查找而言,需要一套辅助操作要求低的技术。甚至在接收对象频繁变化的情况下,这套技术也应当有效。另外,需要一种机制,它能够提高象嵌入式系统这样的有限资源计算环境中运行的虚拟机中的代码执行速度。Therefore, there is a need for a set of techniques that are low in overhead in terms of computational resource processing/execution time, memory, and method search or lookup. This technique should work even when receiving objects change frequently. Additionally, there is a need for a mechanism that can increase the speed of code execution in virtual machines running in resource-constrained computing environments such as embedded systems.

发明内容Contents of the invention

一种基于计算机的系统通过提高方法调用的速度来提高代码执行速度。一个虚拟机包括一装载器、一解释器、线程管理器和其他模块和/或部件。装载器利用方法特征构建一个散列表(hash-table)。解释器利用所构建的散列表来提高搜索方法的处理速度。该解释器构建一个具有一指针的方法调用高速缓冲存储器,并且将其用于一接收器以提高代码执行速度。该高速缓冲存储器提供修正后的守卫条件(guard condition),这些条件使得能够进行更快的高速缓存操作,这种操作使得执行速度更快。线程管理器采用一个用来提高锁定状态过渡速度的深度级。该深度级表示简单锁定状态和扩展锁定状态,这样,消除了对一分离简单锁定状态的需求。锁定状态数目越小,锁定状态过渡速度越快,从而代码执行速度越快。通常,本发明能够在任何虚拟机中实施,例如JAVA虚拟机(JVM)和千字节虚拟机(KVM)环境中。尤其是,本发明能够在具有相对有限计算资源的嵌入式系统中实施。A computer-based system for increasing the speed of code execution by increasing the speed of method calls. A virtual machine includes a loader, an interpreter, a thread manager and other modules and/or components. The loader builds a hash-table using the method signature. The interpreter utilizes the constructed hash table to increase the processing speed of the search method. The interpreter builds a method call cache with a pointer and uses it for a receiver to increase code execution speed. The cache memory provides modified guard conditions that enable faster cache operations that result in faster execution. The thread manager employs a depth level to improve the speed of lock state transitions. This level of depth represents the simple lock state and the extended lock state, thus eliminating the need for a separate simple lock state. The smaller the number of lock states, the faster the lock state transitions, and thus the faster code execution. In general, the present invention can be implemented in any virtual machine, such as the Java Virtual Machine (JVM) and Kilobyte Virtual Machine (KVM) environments. In particular, the invention can be implemented in embedded systems with relatively limited computing resources.

根据下文提供的详细描述,本发明的其他适用范围将变得很明显。应理解的是,表示本发明优选实施例的详细描述和具体实例仅仅用于说明本发明而不是用来限制本发明的范围。Other areas of applicability of the present invention will become apparent from the detailed description provided hereinafter. It should be understood that the detailed description and specific examples, while indicating the preferred embodiment of the invention, are intended for purposes of illustration only and are not intended to limit the scope of the invention.

附图说明Description of drawings

根据详细的说明和附图,能够更完整地理解本发明,这些附图中A more complete understanding of the invention can be obtained from the detailed description and drawings, in which

图1是本发明一个实施例中一虚拟机的方框图;Fig. 1 is a block diagram of a virtual machine in one embodiment of the present invention;

图2A示出一典型的类层次;Figure 2A shows a typical class hierarchy;

图2B示出用于查找加速过程中的一个方法散列表;Fig. 2B shows a method hash table used in the lookup acceleration process;

图3示出一典型方法散列表构建程序;Fig. 3 shows a typical method hash table construction program;

图4描述了一种用来搜索散列表中一方法的典型散列查找程序;Fig. 4 has described a kind of typical hash search program that is used to search a method in the hash table;

图6示出包括到接收器的一个链接的高速缓存入口(cache entry);Figure 6 shows a cache entry including a link to the receiver;

图7示出代表一已知线程管理器的第一自动过程;Figure 7 shows a first automated process representing a known thread manager;

图8示出用来提高多线程应用速度的最优自动过程;Figure 8 illustrates an optimal automatic process for increasing the speed of a multi-threaded application;

图9示出用来表示被继承方法调用中各改进的典型类层次76;Figure 9 shows a typical class hierarchy 76 used to represent improvements in inherited method calls;

图10示出本发明一个实施例中比较方法调用时间的柱形图;Figure 10 shows a histogram comparing method call times in one embodiment of the present invention;

图11示出一饼分图,它表示本发明一个实施例中的加速度/加速变化率。Figure 11 shows a pie chart showing jerk/jerk rate in one embodiment of the invention.

具体实施方式Detailed ways

以下对优选实施例的描述实际上仅仅是示例性的,其决不用来限制本发明、其应用或者用途。The following description of preferred embodiments is merely exemplary in nature and is in no way intended to limit the invention, its application or uses.

一个面向对象(“00”)的程序由包含数据成员和对这些数据成员起作用的方法的各个类组成。这样,一个00程序中的一个方法是一给定类的一部分。前面所表示/定义类的对象可以是例示的。每一个给定类式的各个示例对象拥有在给定类表示/定义中表示的数据成员。通常,那些是给定类式一部分的方法对例示对象起作用。An object-oriented ("00") program consists of classes that contain data members and methods that act on those data members. Thus, a method in an OO program is part of a given class. Objects of the previously denoted/defined classes may be instantiated. Each instance object of a given class has the data members represented in the given class representation/definition. Usually, those methods that are part of a given class act on instantiated objects.

一个例子示出了一00程序中的典型结构。一典型00程序可以有两个类,它们分别称为类A和类B,其中类B继承类A,或者由类A派生。类A可以定义一个方法m,由于这种继承性,类B也将方法m作为其一部分。类A式的对象将方法m作为它们的一部分,那么,由于继承性,类B的对象也将方法m作为他们的一部分。各方法特征用来区分如下所述的各方法。An example shows the typical structure in a 100 program. A typical 00 program can have two classes, which are respectively called class A and class B, where class B inherits from class A, or is derived from class A. Class A can define a method m, and because of this inheritance, class B also has method m as part of it. Objects of class A have method m as part of them, then, due to inheritance, objects of class B also have method m as part of them. The method characteristics are used to distinguish the methods described below.

00环境通常用一些方法特征来区分任何两个表面上类似的方法,这些特征是利用类名、方法名、各参数和返回类型(return type)形成的。当一执行引擎(execution engine)遇到调用关于一给定对象的方法m时,它利用被调用方法的特征来查找方法表中该方法的定义位置。这种方法定义的搜索是一种时间密集型任务(time Intensive task)。本发明使得方法查找和执行所需的时间最少,同时对任意给定环境的计算资源的需求最少。The 00 environment usually uses some method characteristics to distinguish any two superficially similar methods. These characteristics are formed by using the class name, method name, parameters, and return type. When an execution engine encounters an invocation of a method m on a given object, it uses the characteristics of the called method to find the location in the method table where the method is defined. The search defined by this method is a time-intensive task. The present invention minimizes the time required for method lookup and execution while placing the least demands on the computing resources of any given environment.

00语言如JAVA采用一种频繁的动态发送机制来搜索一被调用方法的定义。该方法可以定义于一个以上的类中。对适当方法定义的搜索是动态进行的。这导致产生一个相当大的执行时间辅助操作。通常,已有的静态和动态技术不适合象嵌入式JAVA这样在相对严格资源约束条件下运行的嵌入式平台。尤其是,这些技术是存储加强型的,对于具有有限存储资源的普通嵌入式系统来说,这不是一个理想的特性。00 languages such as JAVA use a frequent dynamic sending mechanism to search for the definition of a called method. This method can be defined in more than one class. The search for appropriate method definitions is done dynamically. This results in a considerable execution time for auxiliary operations. Usually, the existing static and dynamic technologies are not suitable for embedded platforms like embedded JAVA which run under relatively strict resource constraints. In particular, these techniques are memory-intensive, which is not a desirable characteristic for common embedded systems with limited memory resources.

本发明涉及用来加速00环境中方法调用机制的动态、灵活而有效的技术。为了进行说明,在关于嵌入式系统应用中采用JAVA的虚拟机的上下文描述中讨论这种方法调用加速机制。本领域的那些技术人员会理解的是,采用JAVA的嵌入式系统仅仅用作解释说明,而不是限制性的。本发明可以在任何面向对象的环境中运行和/或应用。本发明的加速技术覆盖方法调用过程的多个方面,例如查找方法、高速缓存方法和同步的方法。以下把一个虚拟机作为将本发明技术用于本发明一个实施例的平台进行描述。The present invention relates to a dynamic, flexible and efficient technique for accelerating the method invocation mechanism in the 00 environment. For illustration, this method call acceleration mechanism is discussed in the context of a virtual machine using JAVA in an embedded system application. Those skilled in the art will understand that the embedded system using JAVA is for illustration only and not for limitation. The present invention can be run and/or applied in any object-oriented environment. The acceleration technique of the present invention covers multiple aspects of the method invocation process, such as lookup methods, cache methods, and synchronized methods. A virtual machine is described below as a platform for applying the technology of the present invention to an embodiment of the present invention.

图1是本发明一个实施例中一虚拟机10的方框图。虚拟机10与一操作系统12密切配合工作。一装载器(loader)14把要执行的代码装入虚拟机10中。装载器14包括诸如散列编制器(hash builder)16和散列查表18之类的散列管理模块。校验器(verifier)20校验所装入的类和代码是否有可能的错误。装载器14还装载来自语言类库18和自然类库(native class library)24的任何程序和/或类。FIG. 1 is a block diagram of a virtual machine 10 in one embodiment of the present invention. The virtual machine 10 works closely with an operating system 12 . A loader (loader) 14 loads the code to be executed into the virtual machine 10 . Loader 14 includes hash management modules such as hash builder 16 and hash lookup table 18 . A verifier 20 verifies loaded classes and codes for possible errors. Loader 14 also loads any programs and/or classes from language class library 18 and native class library 24.

解释器26解释并执行装载器14所装入的代码。高速缓冲存储器28和高速缓存信息处理器30是解释器26的一部分,它们用来高速缓存方法调用命令。堆栈管理和无用单元回收模块32被解释器26用来创建和破坏堆栈上的对象。解释器26用线程管理器34来控制正在执行的代码的线程操作。由于各种线程在代码执行的过程中竞争访问各对象,所以线程管理器34对各对象执行锁定和解锁操作。另外,线程管理器34还管理线程切换。Interpreter 26 interprets and executes code loaded by loader 14 . Cache memory 28 and cache information handler 30 are part of interpreter 26 and are used to cache method call commands. The stack management and garbage collection module 32 is used by the interpreter 26 to create and destroy objects on the stack. Interpreter 26 uses thread manager 34 to control the threading operations of the code being executed. As various threads compete to access objects during code execution, thread manager 34 performs locking and unlocking operations on objects. In addition, thread manager 34 also manages thread switching.

以上关于虚拟机10的描述涉及一种普通的虚拟机。这样一个普通虚拟机10的具体例子是JAVA虚拟机(JVM)。作为另一个例子,现提及一KVM(千字节虚拟机)。KVM通常用于需要覆盖区小的JVM的嵌入式系统应用环境中。在KVM或JVM中,装载器14作为一个类文件装载器工作,它装载系统和用户定义的类。另外,装载器14构建常数池(constant pool)和类文件结构,并且与类和代码校验器20相互作用,类和代码校验器20在本例中将校验所装载字节码的模式安全性(type safety)。解释器26用来解释一个所装载类文件的字节码。线程管理器34管理应用线程。本领域的那些技术人员会理解的是,以上对JVM和KVM的描述用于解释,他们有助于理解本发明,但并不是限制性的。下面描述方法查找的加速。The above description about the virtual machine 10 relates to a common virtual machine. A specific example of such a common virtual machine 10 is the Java Virtual Machine (JVM). As another example, a KVM (kilobyte virtual machine) is mentioned. KVM is typically used in embedded system application environments that require a JVM with a small footprint. In KVM or JVM, the loader 14 works as a class file loader, which loads system and user defined classes. In addition, the loader 14 builds a constant pool and class file structure, and interacts with a class and code verifier 20, which in this example will verify the schema of the loaded bytecode Safety (type safety). Interpreter 26 is used to interpret the bytecode of a loaded class file. The thread manager 34 manages application threads. Those skilled in the art will appreciate that the above descriptions of JVM and KVM are for explanation, and they are helpful for understanding the present invention, but not for limitation. The speedup for method lookup is described below.

图2A示出一典型类层次36。类A38包括方法‘m’。类B40是父类A38的子类。类B40包括方法m、m1和m2。类B40从类A38继承了方法m。下面描述这种典型类层次36的基于散列表的查找。Figure 2A shows a typical class hierarchy 36. Class A38 includes method 'm'. Class B40 is a subclass of parent class A38. Class B40 includes methods m, m1 and m2. Class B40 inherits method m from class A38. A hash table based lookup of such a typical class hierarchy 36 is described below.

图2B示出用于查找加速过程中的方法散列表42。虚拟机的装载器14(见图1)为上述类层次的每一个虚拟方法表构建一个散列表42。通过象散列法这样的直接访问技术,提高方法表查找速度。它是利用适当的散列技术和一有效的散列函数(hashing function)实现的:Figure 2B shows the method hash table 42 used in the lookup acceleration process. The loader 14 of the virtual machine (see FIG. 1 ) builds a hash table 42 for each virtual method table of the above class hierarchy. Speed up method table lookups through direct access techniques like hashing. It is implemented using appropriate hashing techniques and an efficient hashing function:

可以以多种方式构建方法特征(图中未示)。例如,可以用方法的名称及其形式参数的数目和类型来构建一个方法特征。散列表42的每一个索引对应于一个结果,该结果是将一散列函数用于该方法特征得到的。应当仔细选择散列表42的大小,以便令其覆盖区小,同时使各方法特征之间的冲突最小,从而获得更有效和灵活的查找机制。由于通过采用散列法访问的方式对所提供的方法表直接访问,所以能够实现有效性。由于能够调整散列表42的大小以使加速与覆盖区之比最佳,所以能够实现灵活性。Method features (not shown in the figure) can be constructed in various ways. For example, a method signature can be constructed with the name of the method and the number and types of its formal parameters. Each index of the hash table 42 corresponds to a result obtained by applying a hash function to the method feature. The size of the hash table 42 should be chosen carefully so that its footprint is small while minimizing collisions between method features, resulting in a more efficient and flexible lookup mechanism. Efficiency can be achieved due to the direct access to the provided method table by means of hash method access. Flexibility is enabled because the hash table 42 can be sized to optimize the ratio of speedup to footprint.

在装载一类的过程中,散列编制器16构建一个散列方法表。根据方法特征计算散列。散列表42中的每一入口由两个部分组成。第一个部分是一标志位(flag),该标志位表示该类是否含具有这样一个定义的方法。在本例中,示出第一部分441-445。在第一部分441和444中存在标志“1”就表示,对于其方法特征散列在第一第一部分441和444的散列索引上的那些方法来说,与方法定义的链接是有用的。In the course of loading a class, hash builder 16 builds a table of hashing methods. Computes a hash based on method characteristics. Each entry in hash table 42 consists of two parts. The first part is a flag that indicates whether the class contains a method with such a definition. In this example, first portions 44 1 - 44 5 are shown. The presence of a flag "1" in the first parts 441 and 444 indicates that, for those methods whose method signatures are hashed on the hash index of the first first part 441 and 444 , the link to the method definition is useful.

第二部分是一个去方法定义的指针。在有冲突的情况下,该第二部分是一个去方法定义列表的指针。这里,第二部分461是第二方法m2的单个方法定义,因为没有其他方法特征散列至第一部分441的散列位置。但是,第一部分444散列位置的第二部分是一冲突列表,因为方法m和m1各自的两个方法特征散列到同一个第一位置444上。因此,分别将方法m和m1方法定义的冲突列表表示为第二部分462和463The second part is a pointer to the method definition. In case of a conflict, the second part is a pointer to the method definition list. Here, the second part 46 1 is a single method definition for the second method m2, since no other method characteristics hash to the hash position of the first part 44 1 . However, the second part of the first part 444 of hash locations is a collision list, since the two method signatures of methods m and m1 each hash to the same first location 444 . Thus, the conflicting lists of method definitions for method m and m1 are denoted as second parts 46 2 and 46 3 , respectively.

图3示出一典型的方法散列表构建程序。装载器14(见图1)可以令一内置散列编制器16(见图1)构建散列表42(见图2B),或者该散列编制器16可以是一外部可调用程序。本领域的那些技术人员会理解的是,装载器14内部或外部的散列构建程序的位置并不以任何方式限制本发明。以下详细解释对散列表42的构建和散列编制器16的工作。Fig. 3 shows a typical method hash table construction procedure. Loader 14 (see FIG. 1 ) may cause a built-in hash builder 16 (see FIG. 1 ) to build hash table 42 (see FIG. 2B ), or the hash builder 16 may be an externally callable program. Those skilled in the art will appreciate that the location of the hash building program, internal or external to loader 14, does not limit the invention in any way. The construction of the hash table 42 and the operation of the hash generator 16 are explained in detail below.

散列编制器16处理装载器14所装入的类。对于给定装入类中的每一个方法来说,散列编制器16根据该方法的特征计算一个散列。利用所产生的散列,散列编制器16得到散列表42中散列索引处的元素(element)。在一方法定义已经存在于所访问散列位置上的情况下,如该散列索引处标志位所确定的那样,那么为新方法创建一冲突入口。但是如果该散列索引处的标志位是“OFF”,指示没有任何方法入口,那么在所计算的散列索引处将该方法记入散列表42中。Hash builder 16 processes classes loaded by loader 14 . For each method in a given loaded class, hash builder 16 computes a hash based on the characteristics of that method. Using the generated hash, hash generator 16 obtains the element at the hash index in hash table 42 . In the event that a method definition already exists at the accessed hash location, as determined by the flag at that hash index, then a conflict entry is created for the new method. But if the flag bit at the hash index is “OFF”, indicating that there is no method entry, then the method is recorded in the hash table 42 at the calculated hash index.

图4描述了一种用来搜索散列表中一方法的典型散列查找程序。散列查表18(见图1)采用一散列值,该散列值是将一散列函数用于访问散列表42(见图2B)中相应入口/索引的方法特征而得到的。采用该散列值,散列查表18确定所访问散列索引/入口处的标志位值。如果与该入口有关的标志位是0N(如图2B中‘1’所示),那么由于有该入口的第二部分,它访问该方法定义。标志位的OFF状态(如图2B中‘0’所示)表示该类没有执行这样一个方法,搜索指向一超类。Figure 4 depicts a typical hash lookup procedure used to search for a method in a hash table. The hash lookup table 18 (see FIG. 1 ) employs a hash value obtained by applying a hash function to the method characteristics of the corresponding entry/index in the hash table 42 (see FIG. 2B ). Using this hash value, the hash look-up table 18 determines the value of the flag bit at the accessed hash index/entry. If the flag associated with the entry is ON (shown as '1' in Figure 2B), then it accesses the method definition because of the second part of the entry. The OFF state of flag bit (shown in ' 0' among Fig. 2B) represents that this class does not carry out such a method, and search points to a superclass.

与基于简单表的搜索相比,基于散列的方法定义访问方式使得搜索时间更快。这种查找方法加速取决于散列表尺寸。较大的散列表尺寸需要较大的存储空间,但是使冲突最小。另一方面,较大的散列表尺寸可能在存储管理(分配、无用单元回收、压缩等等)方面导致产生附加开销。The hash-based approach to defining access makes search times faster compared to simple table-based searches. The speedup of this lookup method depends on the size of the hash table. Larger hash table sizes require larger storage space, but minimize collisions. On the other hand, larger hash table sizes may cause additional overhead in storage management (allocation, garbage collection, compaction, etc.).

本领域的那些技术人员会理解的是,本发明可以以多种方式实施。例如,在一个实施例中,虚拟机10可以构建成包括必要的基于散列的查找元素。作为选择,一传统的虚拟机可以如下所述修改成提供基于散列的查找。Those skilled in the art will appreciate that the present invention can be practiced in various ways. For example, in one embodiment, virtual machine 10 may be constructed to include the necessary hash-based lookup elements. Alternatively, a conventional virtual machine can be modified to provide hash-based lookups as described below.

上述查找加速可以在一个传统的嵌入式JAVA虚拟机内实施,例如在以下的KVM(千字节虚拟机)中实施。普通KVM中的方法查找机制是线性的,即,它采用了一个顺序访问的方式。基于散列的查找在用于普通KVM中的线性方法查找之上具有更好的性能。这样一个机制的执行将影响虚拟机10(见图1)的两个部分:装载器14和解释器26。装载器修改成构建每一个所装入类的散列表42。解释器修改成利用散列表42来执行快速而直接的访问查找。The above search acceleration can be implemented in a traditional embedded JAVA virtual machine, for example, in the following KVM (kilobyte virtual machine). The method lookup mechanism in normal KVM is linear, i.e., it uses a sequential access approach. Hash based lookups have better performance on top of linear approach lookups used in normal KVM. The implementation of such a mechanism will affect two parts of virtual machine 10 (see FIG. 1 ): loader 14 and interpreter 26 . The loader is modified to build a hash table 42 for each loaded class. The interpreter is modified to utilize the hash table 42 to perform fast and direct access lookups.

动态技术存在于前面查找的高速缓存结果中。采用高速缓冲存储器的技术消除了对创建大分派表的需要,这就减少了存储的辅助操作,缩短了表创建时间。全程高速缓存技术存储前面的查找结果。在一全程高速缓存表中,每一入口由三个一组组成(接收类、选择器和方法地址)。接收类和选择器用来计算高速缓冲存储器中的一个索引。如果当前类和方法名与所计算索引处高速缓存入口内的那些匹配,那么执行该方法地址处的代码。因此,避免了方法查找。否则,采用一默认分派技术(通常是DTS),而在该搜索的结尾处,把新的三个一组加到该高速缓存表上,将控制转移给所找到的方法。这种算法所需的运行时间存储量很小,通常是高速缓冲存储器的固定量和DTS技术的辅助操作(overhead)。接收类的频繁变化可能会使执行速度放慢。Dynamic techniques exist in the cached results of previous lookups. Using cache memory technology eliminates the need to create large dispatch tables, which reduces storage overhead and table creation time. Full cache technology stores previous lookup results. In a global cache table, each entry consists of triplets (receiver class, selector, and method address). Receiver classes and selectors are used to compute an index in the cache. If the current class and method names match those in the cache entry at the computed index, then the code at the method address is executed. Thus, method lookup is avoided. Otherwise, a default dispatch technique (usually DTS) is used, and at the end of the search, a new triplet is added to the cache table, transferring control to the method found. The amount of run-time storage required for such an algorithm is small, usually a fixed amount of cache memory and the overhead of the DTS technique. Frequent changes in the receiving class can slow down execution.

图5示出一种用来存储方法调用命令的已有高速缓冲存储器布局。以一有代表性的格式示出高速缓存入口48,下面描述其内容。内容链接50是一去被调用方法的指针。CodeLoc 52是去调用过该方法的指令的指针。原始参数54代表该方法最初被调用时所用的参数。原始指令56指向用来调用该方法的指令。在传统的内联(Inline)高速缓存技术(如KVM中执行的技术)中,只有去方法定义的指针存储在高速缓存入口48中。下面描述修改后的高速缓冲入口结构和高速缓存处理机制。Figure 5 shows an existing cache layout for storing method call commands. Cache entry 48 is shown in a representative format, the contents of which are described below. The content link 50 is a pointer to the called method. CodeLoc 52 is a pointer to the instruction that called the method. The original parameter 54 represents the parameter with which the method was initially called. Raw instruction 56 points to the instruction used to invoke the method. In conventional inline caching technology (such as the technology implemented in KVM), only pointers to method definitions are stored in the cache entry 48 . The modified cache entry structure and cache processing mechanism are described below.

图6示出包括到接收器的一个链接的高速缓存入口58。把调用一方法所涉及的一个对象称为‘接收器’,因为它接收来自其他对象的方法调用请求。接收器指针60指向该接收器。高速缓存入口58的其他成员类似于上述高速缓存入口48。高速缓存入口48除了高速缓存所述的方法调用详细内容外,还高速缓存指向接收器的链接或指针。当调用一方法时,将接收器的类与所调用方法的类作比较。如果这两类相等同,那么由于有该高速缓存入口而重新得到该方法定义。如果不等同,则进行动态查找以在该类层次中搜索该方法定义。这种高速缓冲存储器布局的修改提高了如下所述方法查找过程的速度。Figure 6 shows a cache entry 58 including a link to a receiver. An object involved in invoking a method is called a 'receiver' because it receives method call requests from other objects. Receiver pointer 60 points to the receiver. The other members of cache entry 58 are similar to cache entry 48 described above. Cache entry 48 caches links or pointers to receivers in addition to caching the method call details as described. When a method is called, the receiver's class is compared to the class of the called method. If the two classes are equal, then the method definition is retrieved due to the cache entry. If not, a dynamic lookup is performed to search for the method definition in the class hierarchy. This modification of the cache layout improves the speed of the method lookup process as described below.

可以用一高速缓存方式提高方法调用速度。一种内联高速缓存技术能够利用一修改的高速缓冲存储器布局显著提高程序执行速度。这种内联高速缓存技术在于,在每一个调用位置上,自己将前面查找的结果(方法地址)高速缓存在代码中。内联高速缓冲存储器通过借助默认方法查找方式找到的方法直接调用操作来重写调用指令,从而改变该调用指令。内联高速缓冲存储器假定接收器的类频繁改变,但是当不是这种情况时,内联高速缓存技术可以提供缓慢的执行时间。A cache method can be used to improve the method calling speed. An inline cache technique can significantly increase program execution speed using a modified cache memory layout. This inline caching technique is to cache the previously searched result (method address) in the code at each calling location. The inline cache changes the call instruction by overwriting the call instruction with a method direct call operation found by the default method lookup. Inline caching assumes that the receiver's class changes frequently, but when this is not the case, inline caching techniques can provide slow execution times.

通过避免接收器的类与所调用方法的类之间有一失配时的许多动态查找操作,这种内联高速缓存技术可以得到显著改善。万一发生这样的失配,如果高速缓存处理器30能够检查出接收器没有改变,那么可以从该高速缓冲存储器中重新得到该方法定义。这可以通过以下步骤进行:将一指针加到该高速缓存结构中的接收器上;修改守卫高速缓存恢复的条件。This inline caching technique can be significantly improved by avoiding many dynamic lookup operations when there is a mismatch between the receiver's class and the called method's class. In the event of such a mismatch, the method definition can be retrieved from the cache if the cache processor 30 can check that the receiver has not changed. This can be done by adding a pointer to the receiver in the cache structure; modifying the condition of the guard cache restore.

以上描述了高速缓存入口58中接收指针60的添加。可以将高速缓冲存储器的守卫条件修改成利用接收指针60的存在。当调用一方法时,高速缓存处理器30检查下述的守卫条件。Addition of the receive pointer 60 in the cache entry 58 has been described above. The guard condition of the cache can be modified to take advantage of the presence of the receive pointer 60 . When calling a method, the cache processor 30 checks the following guard conditions.

第一守卫条件是,一给定高速缓存入口58中的接收器的类是否等于所调用方法的类。第二和另一个守卫条件是,当前接收器是否等于接收指针60所指向的高速缓存的接收器,即,该接收器是否仍未受到改变。如果满足这些守卫条件中的任意一个,高速缓存处理器30就重新得到该高速缓存入口58,从而在不必经受方法表查找或搜索的情况下,访问该方法定义。本领域的那些技术人员会理解的是,检查接收器是否尚未受到改变的该另一个守卫条件使得高速缓存恢复过程更灵活。该另一个守卫条件要求接收指针60设置在修改后的高速缓存入口58中。The first guard condition is whether the class of the receiver in a given cache entry 58 is equal to the class of the called method. The second and further guard condition is whether the current receiver is equal to the receiver of the cache pointed to by the receive pointer 60, ie whether the receiver is still unchanged. If any of these guard conditions are met, cache processor 30 retrieves the cache entry 58, thereby accessing the method definition without having to undergo a method table lookup or search. Those skilled in the art will understand that this further guard condition of checking whether the receiver has not been changed makes the cache recovery process more flexible. This other guard condition requires that the receive pointer 60 be set in the modified cache entry 58 .

下面描述本发明一个实施例中高速缓存操作的一个例子。在本例中,考虑一对典型的类X和Y(图中未示)。类Y从类X那里继承了一个非静态方法m。在采用类X和Y的一个OOP程序代码中,存在一个指令环(loop),它将被频繁执行。在这样一个指令环中,关于一对象OB而调用方法m,这里OB是类Y一个实例。在第一次调用方法m之后,高速缓存处理器18将存储指向对象OB的接收指针60,还将其他与调用有关的入口存入高速缓存入口58中。对于对方法m后来的调用,接收指针60的类,即,类Y不同于成为类X的所调用方法的类。第一守卫条件,即,高速缓存入口58中接收器的类(类Y)是否等于所调用方法的类(类Y)这一条件将失效,不进行高速缓存恢复操作。但是,第二守卫条件,即,当前接收器是否等于接收指针所指向的高速缓存的接收器这一条件将会得到满足,因为他们都指向同一个对象OB。因此,第二守卫条件便于利用高速缓存入口58中的接收指针对高速缓存方法调用进行更快的查找。An example of cache operation in an embodiment of the present invention is described below. In this example, consider a pair of typical classes X and Y (not shown in the figure). Class Y inherits a non-static method m from class X. In an OOP program code using classes X and Y, there exists a loop of instructions which will be executed frequently. In such an instruction loop, method m is invoked on an object OB , where OB is an instance of class Y. After the first call to method m, cache handler 18 will store receive pointer 60 to object OB and also store other call-related entries in cache entry 58. For subsequent calls to method m, the class that receives the pointer 60, ie, class Y, is different from the class that became the called method of class X. The first guard condition, ie whether the receiver's class (class Y) in the cache entry 58 is equal to the called method's class (class Y) will be invalidated and no cache restore operation will be performed. However, the second guard condition, ie whether the current receiver is equal to the receiver of the cache pointed to by the receive pointer, will be satisfied since they both point to the same object OB . Thus, the second guard condition facilitates faster lookup of cached method calls using the receive pointer in cache entry 58 .

上述条件下对高速缓存技术的比较显示,本实施例中修改后的高速缓存技术具有较好的查找性能。没有接收指针60的高速缓冲存储器(见图5)将对后来每一次方法m的调用进行动态查找,这导致辅助操作量大。这样一个高速缓冲存储器不能利用将接收指针60所指的对象与当前对象作比较的另外一个守卫条件,因为缺少接收指针。另一方面,高速缓存处理器30将简单地测试当前接收器是否等于接收指针60所指向的那个接收器。因此,在无需任何资源昂贵的查找操作的情况下,对于后来对方法m的所有调用来说,将从该高速缓冲存储器中重新得到该方法定义。这样,本发明的这种高速缓存结构和高速缓存处理机制使得速度大大提高。The comparison of the cache technology under the above conditions shows that the modified cache technology in this embodiment has better search performance. The cache memory (see FIG. 5 ) that does not receive the pointer 60 will perform a dynamic search for each subsequent invocation of the method m, which results in a large amount of auxiliary operations. Such a cache cannot take advantage of the other guard condition of comparing the object pointed to by the receive pointer 60 with the current object because of the absence of the receive pointer. On the other hand, cache handler 30 will simply test whether the current receiver is equal to the one pointed to by receive pointer 60 . Thus, for all subsequent calls to method m, the method definition will be retrieved from the cache without any resource-expensive lookup operations. Thus, the cache structure and cache processing mechanism of the present invention greatly improve the speed.

多态内联高速缓存是内联高速缓存技术的一个扩充。编译器产生对特殊存根(stub)程序的一个调用命令.每一个调用位置转到一特定存根函数(stubfunction)。该功能最初是对一方法查找的调用。每次调用该方法查找,就扩展该存根(stub)功能。在最好的情况下,该技术的成本花费在测试和直接跳转。另外,当类层次很大并且接收类频繁改变时,可执行代码能够大大扩充。Polymorphic inline caching is an extension of inline caching technology. The compiler generates a call command to a particular stub program. Each call site goes to a specific stub function (stubfunction). The function is initially a call to a method lookup. Each time the method lookup is called, the stub functionality is expanded. At best, the cost of this technique is spent testing and direct jumps. Also, when the class hierarchy is large and receiving classes change frequently, the executable code can be greatly expanded.

本发明的另一个实施例实现了提供查找加速的异步线程管理器。无需任何外部资源的异步单线程程序可以自由工作,而无需管理当前运行线程的状态或活动。在多个同步线程可以访问相同资源且同时运行的情况下,必须管理各种线程的冲突要求。在执行一同步方法之前,一个线程必须受到与接收对象有关的锁定。如果两个线程试图对同一对象执行该方法,那么这一操作是必须的。锁定对象显示出该执行操作。以下描述一种典型的线程管理器,该模型用一对象锁定表来管理多个线程的冲突要求。Another embodiment of the present invention implements an asynchronous thread manager that provides lookup acceleration. An asynchronous single-threaded program that does not require any external resources can work freely without managing the state or activity of the currently running thread. In situations where multiple simultaneous threads can access the same resource and run concurrently, the conflicting requirements of the various threads must be managed. Before executing a synchronized method, a thread must acquire the lock associated with the receiving object. This is necessary if two threads attempt to execute the method on the same object. The locked object shows the execution action. A typical thread manager is described below, which uses an object lock table to manage conflicting requests from multiple threads.

图7示出代表一已知线程管理器的第一自动过程62。第一自动过程62将对象锁定状态表示为圆圈,将状态转换表示为连接自动过程状态的有向线段。第一自动过程62由状态A-E组成,它们表示一个给定对象的锁定状态。状态A64代表一个未锁定状态;状态B66代表一个简单锁定状态;状态C68代表一个扩展状态;状态D70代表一个监视状态;状态E72代表一个例外状态。各转换由以下字母标明:‘u’、‘s’、‘e’、‘m’和‘x’。尤其是,这些字母代表以下操作:u-设定_未锁定;s-设定_简单_锁定;e-设定_扩展_锁定;m-设定_监视;x-提出_例外。Figure 7 shows a first automated process 62 representative of a known thread manager. The first automated process 62 represents object locking states as circles and state transitions as directed line segments connecting the states of the automated process. The first automatic process 62 consists of states A-E, which represent the locking state of a given object. State A64 represents an unlocked state; state B66 represents a simple locked state; state C68 represents an extended state; state D70 represents a monitoring state; state E72 represents an exception state. Transformations are identified by the following letters: 'u', 's', 'e', 'm' and 'x'. In particular, these letters stand for the following operations: u - set_unlocked; s - set_simple_locked; e - set_extended_locked; m - set_monitor; x - raise_exception.

在有关给定对象的内容中描述各转换操作的相互作用。最初,对象处与一未锁定状态A64。当一线程试图锁定对象以第一次将对象的锁定状态变为简单锁定状态B66时,执行设定_简单_锁定操作。另外,当另一个线程试图锁定正处于简单锁定状态B66下的同一对象时,对象锁定状态变为扩展的锁定状态‘C’68。该对象一直保持在一扩展状态C68下,直到任何其他的线程试图进一步锁定它为止。从任意给定的状态开始,当第二线程试图锁定一对象同时另一个线程已进行了锁定的时候,可以创建一个监视状态D70。可以进行从任何状态向监视状态D70的转换。从一个同步方法中的退出,引发了从监视状态D70或扩展状态C68的转换。Describe the interaction of transformation operations in context with respect to a given object. Initially, the object is in an unlocked state A64. A set_simple_lock operation is performed when a thread attempts to lock an object to change the lock state of the object to simple lock state B66 for the first time. Additionally, when another thread attempts to lock the same object that is in simple locked state B66, the object locked state changes to extended locked state 'C'68. The object remains in an extended state C68 until any other thread attempts to lock it further. From any given state, a watch state D70 may be created when a second thread attempts to lock an object while another thread already has the lock. A transition from any state to monitor state D70 can be made. Exit from a synchronous method triggers a transition from monitor state D70 or extended state C68.

从任何给定状态向任意其他状态的转换可以有惟一的例外,这个例外就是例外状态E72。当出现一个例外信号时,对象达到例外状态E72。通过将一转换指令或命令发送给例外状态E72,也不可能退出该例外状态E72。对于其他状态,即,A-D来说,通过发送一个适当的转换指令或信号,可以转换到其他状态或转换到其自身。The only exception to this transition from any given state to any other state is exception state E72. When an exception signal occurs, the object reaches exception state E72. It is also not possible to exit the exceptional state E72 by sending a switching instruction or command to the exceptional state E72. For other states, ie A-D, it is possible to transition to other states or to itself by sending an appropriate transition command or signal.

图8示出用来提高多线程应用速度的最优自动过程。它改进了虚拟机10(见图1)中所用的同步技术。通过从图7所示的自动过程中去除简单锁定状态B66,该线程管理器避免了来自和去向简单锁定状态B66的转换,因此直接从未锁定状态A64转换到锁定状态C68。一深度指示器(图中未示)用来指示如下所述的锁定水平。Figure 8 shows an optimal automatic process for increasing the speed of a multi-threaded application. It improves upon the synchronization techniques used in virtual machine 10 (see FIG. 1). By removing simple locked state B66 from the automatic process shown in FIG. 7, the thread manager avoids transitions to and from simple locked state B66, thus transitioning directly from unlocked state A64 to locked state C68. A depth indicator (not shown) is used to indicate the lock level as described below.

当一线程试图第一次锁定一对象时,该对象从未锁定状态A64转为简单锁定状态B66(见图7)。这种情况下,将深度(对象被锁定的次数)设为一。如上所述,一对象从简单锁定状态B66转为扩展锁定状态C68。当一线程试图第二次锁定该对象时,深度增加到二,指示去向扩展锁定状态C68的转换。扩展锁定状态C68可以看成这样一种状态,即,其中深度水平可以大于或等于一。这样,采用一个深度指示器,可以消除对简单锁定状态B66的需求。When a thread attempts to lock an object for the first time, the object transitions from the unlocked state A64 to the simply locked state B66 (see FIG. 7). In this case, set the depth (the number of times the object is locked) to one. As described above, an object transitions from simple locked state B66 to extended locked state C68. When a thread attempts to lock the object a second time, the depth increases to two, indicating a transition to the extended locked state C68. The extended locked state C68 may be considered a state in which the depth level may be greater than or equal to one. Thus, with a depth indicator, the need for a simple locked state B66 can be eliminated.

简单锁定状态的取消改进了线程性能,因为可以避免执行某些部分代码。另外,避免了从简单锁定状态向扩展锁定的转换,使该线程管理器更有效。Cancellation of simple lock state improves thread performance because certain parts of code can be avoided from executing. In addition, transitions from simple locking state to extended locking are avoided, making this thread manager more efficient.

图9示出用来表示被继承方法调用中各改进的典型类层次76。这里,基本类是类P78。类Q80继承并派生了类P78。类Q80扩展了类P78的被继承方法m()。类R82派生了类Q80,类S84进一步扩展了类R82。在类S84的主()方法中,对一个新目标‘o’的类型S()进行初始化。把被继承方法‘m’用作进一步描述中的一个例子,用以说明加速的结果。本领域的那些技术人员会理解的是,以上对类层次76的描述是一种典型类层次的实例,它并不以任何方式限制本发明。通常,本发明所介绍的技术表现出能够在JAVA程序执行速度方面进行高达约27%的加速。下面的描述概括了上述类层次,用以说明应用本发明的原理所得到的典型性能增强效果。Figure 9 shows a typical class hierarchy 76 used to represent improvements in inherited method calls. Here, the base class is class P78. Class Q80 inherits and derives class P78. Class Q80 extends the inherited method m() of class P78. Class R82 derives class Q80, and class S84 further extends class R82. In the main() method of class S84, a new object 'o' of type S() is initialized. Use the inherited method 'm' as an example in the further description to illustrate the results of the speedup. Those skilled in the art will appreciate that the above description of class hierarchy 76 is an example of a typical class hierarchy and does not limit the present invention in any way. Typically, the techniques presented in this invention have been shown to enable up to about 27% speedup in the execution speed of JAVA programs. The following description summarizes the class hierarchy described above to illustrate typical performance enhancements obtained by applying the principles of the present invention.

图10示出本发明一个实施例中用来比较原始方法调用与最佳方法调用的柱形图86。假定在KVM环境下执行原始方法调用88,而用本发明的虚拟机10(见图1)执行最佳方法调用90。柱形图86的X轴代表散列表尺寸42(见图2B),而Y轴代表执行时间。如X轴上所示,散列表尺寸42从11个单位变化到29个单位。最佳方法调用90在散列表所有的尺寸42上都表现出有所改善的性能。如Y轴上所示,对于相同的方法调用来说,最佳方法调用90需要约500毫秒的时间,而原始方法调用88需要约800毫秒的时间。因而,与KVM方法调用时间相比,本发明的最佳方法调用90具有改善的执行时间。本领域的那些技术人员会理解的是,以上关于方法调用时间的比较是示例性的并具有代表性特征,但是它并不以任何方式限制本发明。Figure 10 shows a histogram 86 used to compare the original method call to the optimal method call in one embodiment of the present invention. It is assumed that the original method call 88 is performed under the KVM environment, while the optimal method call 90 is performed with the virtual machine 10 (see FIG. 1 ) of the present invention. The X-axis of the histogram 86 represents hash table size 42 (see FIG. 2B ), while the Y-axis represents execution time. As shown on the x-axis, the hash table size 42 varies from 11 units to 29 units. The best method call of 90 shows improved performance on all hash table sizes of 42. As shown on the Y-axis, the optimal method call 90 takes about 500 milliseconds, while the original method call 88 takes about 800 milliseconds for the same method call. Thus, the optimal method call 90 of the present invention has improved execution time compared to the KVM method call time. Those skilled in the art will understand that the above comparison of method call times is exemplary and representative, but it does not limit the present invention in any way.

图11示出一饼分图92,它表示本发明一个实施例中的加速度/加速变化率。标记94指示出散列表42(见图2B)的尺寸,最终的加速表示为一个相应的扇形区96。该饼分图92反映出将仿形技术(profiling technique)用于图9所示和上述的代码片断的情况。饼分图92示出,当散列表42的尺寸为最佳时,可以有较好的执行时间。在本例中,散列表的最佳尺寸约为29个单位,其相应的执行时间是27.91个单位。这可以与这样一种情况作对照,即,散列表42的尺寸是11,执行时间增加到35.97。采用本发明的灵活技术,可以选择最佳的散列表42的尺寸,从而使冲突最少,并且所需要的存储器覆盖区也有所减小。下面描述本发明总的特征。Figure 11 shows a pie chart 92 showing acceleration/jerk rate in one embodiment of the present invention. Reference 94 indicates the size of the hash table 42 (see FIG. 2B ), and the resulting acceleration is represented by a corresponding sector 96 . The pie chart 92 reflects the use of profiling techniques for the code snippets shown in FIG. 9 and described above. The pie chart 92 shows that when the size of the hash table 42 is optimal, there can be better execution times. In this example, the optimal size of the hash table is about 29 units, and its corresponding execution time is 27.91 units. This can be contrasted with the case where the size of the hash table 42 is 11, the execution time increases to 35.97. Using the flexible technique of the present invention, the optimal size of the hash table 42 can be chosen so that collisions are minimized and the required memory footprint is reduced. The general features of the present invention are described below.

本发明优选用于在嵌入式系统中实施的面向对象系统,与较大的系统相比,嵌入式系统中的计算资源有限。由于系统通常是实时的,所以嵌入式系统中性能增强得很理想。另外,本发明提供灵活的方法,以使性能增强技术的资源要求最佳。这是嵌入式系统中另一个理想的特征,因为它们具有有限的存储器和处理能力。本领域的那些技术人员会理解的是,术语“嵌入式系统”用于一般方式,其覆盖了在某个资源约束条件下运行的任何系统。例如,在其中计算资源具有有限特征的采用蜂窝电话或手表的应用中运行JVM的系统。The invention is preferably used in object-oriented systems implemented in embedded systems where computing resources are limited compared to larger systems. Performance enhancement is ideal in embedded systems since the systems are usually real-time. Additionally, the present invention provides a flexible approach to optimize the resource requirements of performance enhancement techniques. This is another desirable feature in embedded systems since they have limited memory and processing power. Those skilled in the art will understand that the term "embedded system" is used in a general manner covering any system that operates under certain resource constraints. For example, a system running a JVM in an application employing a cell phone or a watch where computing resources are of limited character.

本发明的描述本身仅仅是示例性的,因此,那些不脱离本发明要旨的变换都确定落入本发明的范围内。不认为这些变换脱离本发明的实质和范围。The description of the invention itself is merely exemplary, and therefore, changes that do not depart from the gist of the invention are intended to fall within the scope of the invention. Such changes are not considered to depart from the spirit and scope of the invention.

Claims (20)

1.一种用来提高至少一个程序执行速度的基于计算机平台的系统,该系统包括:1. A computer platform-based system for increasing the speed of execution of at least one program, the system comprising: 一虚拟机,它有一装载器,用于装载一程序;A virtual machine, which has a loader for loading a program; 所述装载器包括一散列编制器和一散列查表模块,所述散列编制器用于构建与至少一个程序类对应的至少一个散列表,所述散列表是利用所述类的至少一个方法的至少一个散列方法特征构建的;The loader includes a hash builder and a hash table lookup module, the hash builder is used to construct at least one hash table corresponding to at least one program class, and the hash table utilizes at least one of the classes at least one hash method characteristic of the method is constructed; 所述散列查表模块用一散列功能为属于一给定程序类的一个给定方法的所述散列方法特征得到一散列值,并用所述散列值搜索所述给定方法的所述散列表。The hash look-up module uses a hash function to obtain a hash value for the hash method characteristics of a given method belonging to a given program class, and uses the hash value to search for the given method The hash table. 2.按照权利要求1的系统,其中所述散列方法特征是通过将一散列函数用于所述类的所述方法一个特征得到的。2. The system according to claim 1, wherein said hash method signature is obtained by applying a hash function to said method signature of said class. 3.按照权利要求2的系统,其中所述散列表包括;3. The system according to claim 2, wherein said hash table comprises; 至少一个散列表索引,它对应于所述被散列方法特征;at least one hash table index corresponding to said hashed method signature; 至少一个方法标志位;和at least one method flag; and 至少一个指针,它用于所述类的所述方法的定义。At least one pointer for the definition of said method of said class. 4.按照权利要求3的系统,其中所述散列表还包括:4. The system according to claim 3, wherein said hash table further comprises: 一冲突列表,它用来处理与所述散列表的一个公共所述索引对应的多个被散列方法特征。a collision list for handling a plurality of hashed method signatures corresponding to a common said index of said hash table. 5.按照权利要求4的系统,其中所述装载器包括一用来更新所述冲突列表的冲突处理器。5. The system of claim 4, wherein said loader includes a conflict handler for updating said conflict list. 6.按照权利要求5的系统,其中所述冲突处理器被优化为能够处理一些冲突的情况,这些情况中,多个被散列方法特征对应于所述散列表的一个公共所述索引。6. The system of claim 5, wherein said conflict handler is optimized to handle conflict cases where a plurality of hashed method characteristics correspond to a common said index of said hash table. 7.按照权利要求6的系统,其中当所述散列查表模块不能找到与所述给定方法的所述散列表入口的位置时,所述散列查表模块搜索所述类的所述冲突列表。7. The system according to claim 6, wherein when said hash look-up module cannot find the location of said hash table entry for said given method, said hash look-up module searches said hash table entry for said class. A list of conflicts. 8.按照权利要求7的系统,其中当所述散列查表模块在所述冲突列表中不能找到与所述给定方法对应的所述散列表入口的位置时,所述散列查表模块搜索所述类的一个超类。8. according to the system of claim 7, wherein when said hash look-up module can not find the position of said hash table entry corresponding to said given method in said collision list, said hash look-up module Searches for a superclass of said class. 9.按照权利要求1的系统,其中所述虚拟机是一千字节虚拟机(KVM),它在与一电子设备有关的存储环境中运行,所述解释器是一字节码解释器。9. The system of claim 1, wherein said virtual machine is a kilobyte virtual machine (KVM) running in a storage environment associated with an electronic device, and said interpreter is a bytecode interpreter. 10.按照权利要求1的系统,其中所述虚拟机是一JAVA虚拟机(JVM)。10. The system of claim 1, wherein said virtual machine is a Java Virtual Machine (JVM). 11.按照权利要求1的系统,其中所述散列表需要有关最佳的存储容量。11. The system according to claim 1, wherein said hash table requires an optimal storage capacity. 12.一种执行一个程序的基于计算机平台的虚拟机,该程序具有至少一个类,该类具有至少一个方法,该虚拟机包括:12. A computer platform-based virtual machine for executing a program, the program having at least one class, the class having at least one method, the virtual machine comprising: 一装载器,包括一散列编制器和一散列查表模块,所述散列编制器用于构建与至少一个程序类对应的至少一个散列表,所述散列表是利用所述类的至少一个方法的至少一个散列方法特征构建的;A loader, including a hash compiler and a hash table lookup module, the hash compiler is used to construct at least one hash table corresponding to at least one program class, and the hash table utilizes at least one of the classes at least one hash method characteristic of the method is constructed; 所述散列查表模块用一散列功能为属于一给定程序类的一个给定方法的所述散列方法特征得到一散列值,并用所述散列值搜索所述给定方法的所述散列表;The hash look-up module uses a hash function to obtain a hash value for the hash method characteristics of a given method belonging to a given program class, and uses the hash value to search for the given method said hash table; 一解释器,它用来执行所述装载器装入的方法,一高速缓冲存储器与所述解释器相关,所述解释器包括至少一个高速缓存入口,所述高速缓存入口存储一在先指向对象的第一链接和一在先指向方法的第二链接;和an interpreter for executing methods loaded by said loader, a cache memory associated with said interpreter, said interpreter comprising at least one cache entry storing a previously pointed object and a second link previously pointing to the method; and 一高速缓存信息处理器,与所述解释器相关,用于,在高速缓存中,当一当前指向对象与所述在先指向对象通过第一链接进行比较的时候,直接通过所述第二链接获得所述方法;和a cache information handler, associated with said interpreter, for, in the cache, directly passing said second link when a currently pointed object is compared with said previously pointed object through said first link obtaining said method; and 所述解释器使用的一线程管理器,所述线程管理器的至少两个线程对该对象起作用,所述线程管理器用一深度水平控制该对象的锁定,其中深度水平中的变化产生至少两个不同锁定状态之间的转换。A thread manager used by the interpreter, at least two threads of the thread manager act on the object, the thread manager controls the locking of the object with a depth level, wherein a change in the depth level produces at least two Transitions between different locking states. 13.一种用来提高至少一个程序执行速度的基于计算机平台的方法,该方法包括:13. A computer platform-based method for increasing execution speed of at least one program, the method comprising: 用一装载器将该程序装入一虚拟机内;loading the program into a virtual machine with a loader; 构建与该程序的至少一个类对应的至少一个散列表;constructing at least one hash table corresponding to at least one class of the program; 用所述类的至少一个方法的至少一个散列方法特征来构建所述散列表;和constructing said hash table with at least one hash method signature of at least one method of said class; and 用一散列查表模块来解释所装入的所述程序,以搜索属于该程序一个给定类的至少一个给定方法。The loaded program is interpreted with a hash look-up module to search for at least one given method belonging to a given class of the program. 14.按照权利要求13的方法,其中构建步骤还包括:14. The method according to claim 13, wherein the constructing step further comprises: 将一散列函数用于所述类的所述方法的一个特征,以得到至少一个被散列方法特征。A hash function is applied to an attribute of said method of said class to obtain at least one hashed method attribute. 15.按照权利要求13的方法,其中解释步骤还包括:15. The method according to claim 13, wherein the interpreting step further comprises: 为与所述给定方法对应的一个散列表入口搜索所述被散列方法表。The hashed method table is searched for a hash table entry corresponding to the given method. 16.按照权利要求13的方法,其中构建步骤还包括:16. The method according to claim 13, wherein the constructing step further comprises: 创建一个冲突列表,用以处理与所述散列表的一个公共索引对应的多个被散列方法特征。A collision list is created for handling hashed method signatures corresponding to a common index of said hash table. 17.按照权利要求16的方法,其中解释步骤还包括:17. The method according to claim 16, wherein the interpreting step further comprises: 当所述散列查表模块无法找到与所述给定方法对应的所述散列表中一入口的位置时,搜索所述类的所述冲突列表。When the hash table lookup module cannot find the location of an entry in the hash table corresponding to the given method, the conflict list of the class is searched. 18.按照权利要求17的方法,还包括:18. The method according to claim 17, further comprising: 优化对所述冲突列表的搜索。A search of the conflict list is optimized. 19.按照权利要求17的方法,还包括:19. The method according to claim 17, further comprising: 当所述散列查表模块无法在所述冲突列表中找到与所述给定方法对应的所述散列表入口的位置时,搜索所述类的一个超类,其中所述类与所述超类有关。When the hash table lookup module cannot find the position of the hash table entry corresponding to the given method in the conflict list, search a superclass of the class, where the class is the same as the superclass class related. 20.按照权利要求13的方法,还包括:20. The method according to claim 13, further comprising: 优化所述散列表的尺寸。Optimize the size of the hash table.
CNB031374654A 2002-08-22 2003-06-24 Acceleration of method call in virtual machine Expired - Fee Related CN1251076C (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
US40526602P 2002-08-22 2002-08-22
US60/405,266 2002-08-22

Publications (2)

Publication Number Publication Date
CN1495608A CN1495608A (en) 2004-05-12
CN1251076C true CN1251076C (en) 2006-04-12

Family

ID=31496001

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB031374654A Expired - Fee Related CN1251076C (en) 2002-08-22 2003-06-24 Acceleration of method call in virtual machine

Country Status (4)

Country Link
US (1) US20040040029A1 (en)
EP (1) EP1394675A3 (en)
JP (1) JP2004086869A (en)
CN (1) CN1251076C (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107133081A (en) * 2016-02-26 2017-09-05 龙芯中科技术有限公司 instruction dispatch method and interpreter

Families Citing this family (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6964039B2 (en) * 2000-12-13 2005-11-08 Esmertec Ag Method to create optimized machine code through combined verification and translation of JAVA™ bytecode
CN100428185C (en) * 2003-10-20 2008-10-22 罗得岛及普罗维登斯属地高等教育管理委员会 Storage server's bottom-up cache structure
EP1872205A4 (en) * 2005-04-18 2008-05-14 Research In Motion Ltd System and method for efficient hosting of wireless applications by encoding application component definitions
US20060242654A1 (en) * 2005-04-22 2006-10-26 Lund Kasper V Process and apparatus for sharing inline caches
US8291395B2 (en) * 2006-03-31 2012-10-16 Apple Inc. Fast function call dispatching
US7836440B2 (en) * 2006-04-27 2010-11-16 Oracle America, Inc. Dependency-based grouping to establish class identity
EP2135159A4 (en) * 2007-03-09 2011-11-30 Objective Interface Systems Inc Optimized code generation through elimination of unused virtual functions
US8132162B2 (en) 2007-07-05 2012-03-06 International Business Machines Corporation Runtime machine analysis of applications to select methods suitable for method level caching
US7949826B2 (en) * 2007-07-05 2011-05-24 International Business Machines Corporation Runtime machine supported method level caching
CN101419549B (en) * 2008-05-13 2012-04-18 飞天诚信科技股份有限公司 Method and device for searching class and function based on Net card
US20100106977A1 (en) * 2008-10-24 2010-04-29 Jan Patrik Persson Method and Apparatus for Secure Software Platform Access
US7685565B1 (en) 2009-03-19 2010-03-23 International Business Machines Corporation Run time reconfiguration of computer instructions
US8612731B2 (en) * 2009-11-06 2013-12-17 International Business Machines Corporation Branch target buffer for emulation environments
US9170825B2 (en) * 2011-04-21 2015-10-27 Oracle International Corporation Interface method resolution for virtual extension methods
US9183111B2 (en) 2011-05-10 2015-11-10 Microsoft Technology Licensing, Llc Methods and computer program products for collecting storage resource performance data using file system hooks
WO2012164439A1 (en) 2011-06-02 2012-12-06 International Business Machines Corporation Handling cross-thread method calls
US9201797B1 (en) * 2013-05-15 2015-12-01 Google Inc. Per-selector dispatch
US9304748B2 (en) * 2013-08-07 2016-04-05 Qualcomm Incorporated Method for controlling inlining in a code generator
US9250891B1 (en) * 2014-10-28 2016-02-02 Amazon Technologies, Inc. Optimized class loading
EP4524731A1 (en) * 2023-09-13 2025-03-19 Flipper Technologies Ltd A memory management unit-less (mmu-less) device and a method for use in preparing software for the mmu-less device
EP4592834A3 (en) * 2023-05-25 2025-10-01 Flipper Technologies Ltd Loading an executable in a memory management unit-less (mmu-less) device
US20240394179A1 (en) * 2023-05-25 2024-11-28 Flipper Technologies Ltd Memory management unit-less (mmu-less) device and related techniques
EP4524725A1 (en) * 2023-09-13 2025-03-19 Flipper Technologies Ltd Techniques for preparation of software for a memory management unit-less (mmu-less) device

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6134603A (en) * 1998-03-20 2000-10-17 Sun Microsystems, Inc. Method and system for deterministic hashes to identify remote methods
US5848423A (en) * 1997-04-23 1998-12-08 Sun Microsystems, Inc. Garbage collection system and method for locating root set pointers in method activation records
JP3627055B2 (en) * 1998-02-10 2005-03-09 インターナショナル・ビジネス・マシーンズ・コーポレーション Cache object selection method, cache discard method, and computer
US6349322B1 (en) * 1998-05-06 2002-02-19 Sun Microsystems, Inc. Fast synchronization for programs written in the JAVA programming language
GB9825102D0 (en) * 1998-11-16 1999-01-13 Insignia Solutions Plc Computer system
US6412108B1 (en) * 1999-05-06 2002-06-25 International Business Machines Corporation Method and apparatus for speeding up java methods prior to a first execution
US7058639B1 (en) * 2002-04-08 2006-06-06 Oracle International Corporation Use of dynamic multi-level hash table for managing hierarchically structured information

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107133081A (en) * 2016-02-26 2017-09-05 龙芯中科技术有限公司 instruction dispatch method and interpreter
CN107133081B (en) * 2016-02-26 2019-12-17 龙芯中科技术有限公司 instruction dispatching method and interpreter

Also Published As

Publication number Publication date
JP2004086869A (en) 2004-03-18
EP1394675A3 (en) 2004-09-29
US20040040029A1 (en) 2004-02-26
EP1394675A2 (en) 2004-03-03
CN1495608A (en) 2004-05-12

Similar Documents

Publication Publication Date Title
CN1251076C (en) Acceleration of method call in virtual machine
US11175896B2 (en) Handling value types
US6658421B1 (en) System and method for detecting release-to-release binary compatibility in compiled object code
US6272674B1 (en) Method and apparatus for loading a Java application program
US8612960B2 (en) Common class loaders
EP3314422B1 (en) Extending a virtual machine instruction set architecture
US6470494B1 (en) Class loader
US9336018B2 (en) Mechanism for class data sharing using extension and application class-loaders
US20050289546A1 (en) Thread synchronization with lock inflation methods and apparatus for managed run-time environments
US20220300264A1 (en) Implementing optional specialization when compiling code
WO1994023360A1 (en) Shared library locating system
US7406687B1 (en) Sharing runtime representation of software component methods across component loaders
US6714991B1 (en) Method and apparatus for implementing fast subclass and subtype checks
US20040015912A1 (en) Method of byte code quickening: quick instructions for method invocation
US7035977B2 (en) Method and system for stack-caching method frames
US7565385B2 (en) Embedded garbage collection
EP1226496B1 (en) System and method supporting type checking of options
US6829686B2 (en) Method and apparatus for bag-to-set, buffering remembered set
US8001541B2 (en) System and method for matching of classpaths in a shared classes system
US11347487B2 (en) Confining reflective access based on module boundaries
US20260017100A1 (en) Designating Memory Regions For Instantiating Objects In Accordance With Memory Allocation Constraints
Debbabi et al. Method call acceleration in embedded Java virtual machines
WO2001035214A2 (en) System and method supporting plural option data structures
HK1000847A (en) System and method for runtime optimization of private variable function calls in a secure interpreter

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
C19 Lapse of patent right due to non-payment of the annual fee
CF01 Termination of patent right due to non-payment of annual fee