GB2336919A - Pre-emptive threading in a virtual machine - Google Patents

Pre-emptive threading in a virtual machine Download PDF

Info

Publication number
GB2336919A
GB2336919A GB9809279A GB9809279A GB2336919A GB 2336919 A GB2336919 A GB 2336919A GB 9809279 A GB9809279 A GB 9809279A GB 9809279 A GB9809279 A GB 9809279A GB 2336919 A GB2336919 A GB 2336919A
Authority
GB
United Kingdom
Prior art keywords
virtual machine
thread
processing system
component
flag
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.)
Withdrawn
Application number
GB9809279A
Other versions
GB9809279D0 (en
Inventor
Emma Eldergill
Timothy Edward Preece
Alan Michael Webb
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.)
International Business Machines Corp
Original Assignee
International Business Machines Corp
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 International Business Machines Corp filed Critical International Business Machines Corp
Priority to GB9809279A priority Critical patent/GB2336919A/en
Publication of GB9809279D0 publication Critical patent/GB9809279D0/en
Publication of GB2336919A publication Critical patent/GB2336919A/en
Withdrawn legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • G06F9/4825Interrupt from clock, e.g. time of day

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The Java specification says that the Java threading model must be pre-emptive. On a platform that does not support pre-emptive threads (such as one which supports co-operative threads) it possible to enter a dead lock when an infinite processing loop occurs in one of the threads. This is solved by the use of a timer interrupt in a Java Virtual Machine to simulate pre-emptive threading on a platform whose native model is not pre-emptive. A timer interrupt informs the Java Virtual Machine when to voluntarily pass control from one thread to another. Further, the method of operation involves use of a virtual machine defined flag (44) which is checked by the threads (40A, 40B) as they run. If the yield flag is set then the thread gives up control of the processing system (34).

Description

1 PRE-EMPTIVE THREADING IN A VIRTUAL MACHINE is 2336919 This invention
relates to pre-emptive threading in a virtual machine. In particular it relates to pre-emptive threading by a Java Virtual Machine (JVM).
BACKGROUND
Java has its origins in a project undertaken by Sun Microsystems to develop a robust programming environment that would meet the technical challenges of the consumer device software environment. The original consumer device projects were eventually abandoned but Java found itself being used on the World Wide Web to enable cross platform operation of programs downloaded from the internet. It is simple to use having similar features to C++ such as the basic object orientated technology but without some of the more complex features.
Typically, Java programs are compiled into classes which can be loaded and executed by a Java Virtual Machine (JVM) (see Figure 1). The JVM provides an instruction set, memory management and program loading capability that is independent of the hardware platform on which it has been implemented. The Java source code is compiled into architecture independent object code or byte code and the byte code is interpreted by a JVM on the target platform. Java is designed to be portable and follows some defined portability standards, which intend the source code to be write once, run anywhere. Multithreading is built into the Java language and allows users to improve interactive performance by allowing operations to be performed while continuing to process user actions.
The JVM is a software computing machine, effectively it simulates a hardware machine that processes Java byte code. Java source code is compiled by 'Javac', a Java compiler, into Java byte code. The byte code is interpreted and processed by a JVM such as an 052 JVM running on a Intel personal computer platform or a VMESA JVM running on a VMESA platform (see Figure 2). The JVM includes components for interpreting the byte code, garbage collection, and for managing multiple threads and synchronisation.
Multithreading is similar to multitasking, but whereas multitasking allows many applications to run on the same system in several processes, multithreading allows many routines (threads) in one application to run 2 is essentially in parallel within one process. Figure 3 represents the memory space in a multithreading environment including: a stack for each thread containing the variables of the program procedure run by the thread and other information related to the procedure; the program byte code and data used by the program or procedure. Each thread has associated registers in the virtual machine including a stack pointer for keeping the process place within the stack when the thread is running and a program counter for keeping the place within the main program from where the procedure is called. The virtual machine can alternate between the two threads to process the procedures apparently at the same time because there is a stack and registers for each thread. A non-threading environment would only have one stack pointer and one set of registers associated with the program code and global data. A multitasking environment would have one stack register, registers, programme code and data for each task. Multithreading is therefore a memory efficient method of running several processes in parallel as there is a single copy of the program code and global data and multiple stack pointers and registers for the multiple threads (a one to many relationship between program code including data and its threads).
There are two main types of multithreading: co-operative multithreading and pre-emptive multithreading. in a co-operative multithreading system a thread will continue until the thread calls an operating system API which causes it to give up control. At that point control of the processing passes back to the co-operative multithreading system so that control may be passed on to another thread. In a pre-emptive multithreading system the 0/5 or environment causes a thread to give up control of the processing at some undefined point in the processing. Another thread takes control for a while and may be forced to give control back to the original thread before its processing is finished. In effect two processes are run in parallel with the processing switching between them.
A virtual machine which currently emulates pre-emptive threading (on top of a co-operative threading operating system), is the Microsoft Windows 3. 1 JVM (see Figure 4). A personal computer 10, including an Intel Pentium microprocessor, RAM memory, hard and soft disk, keyboard, mouse and VDU, has Windows 3.1 operating system 12 installed. on top of the operating system runs a Windows 3.1 Java Virtual Machine 14 which interprets Java byte code and uses Windows 3.1 operating system calls during execution of the code. Windows 3.1 operating system 12 is a 3 3 single process operating system (indicated by Win 3.1 single process component 15) and uses a co-operative threading model. The Java threading therefore relies on a JVM pre-emptive threading component 16 inside the Windows JVM 14 to provide pre-emptive threading functionality. The pre- emptive component 16 is an interface between the Win 3.1 single process component 15 and first and second JVM thread processing components 18A,B. Each thread processing component 18A,B has a stack pointer, program counter, registers and stack for processing java byte code held in the stack using the single processing component 15 of the operating system. Each of the thread components has a counter 20A,B which is used by the respective thread component 18A to indicate when the thread gives up control of its processing. For instance, the first counter 20A increments after a Java byte code instruction is processed in the first thread component 18A and after a set number of increments the first thread component 18A will stop processing and pass control back to the multithreading component 16 which then passes control to the second thread 18B. The counter 20B increments each time an instruction is processed in the second thread 18B and again, after a set number of increments, the second thread 18B will stop processing and pass control back to the multithreading component 16 which will reassign control.
one problem with such an arrangement is that it does not scale well from slow microprocessor to fast microprocessor. Thread processing is used for both real time functions and time independent functions. With a faster microprocessor, the counters will increment faster, and so the threads will give up control faster which will produce increased and unnecessary swapping in the processing unless other measures are taken. Another problem with the prior art solution is that the counter is hard coded ito the J%Y, and as such may not be configured for variable pre-emptive timing.
SUMARY OF THE INVENTION
In a first aspect of the invention there is provided a virtual machine for operating with a computer processing system, the virtual machine comprising: first and second thread processing components adapted to process respective first and second procedures of computer code using the computer processing system, only one of the thread components having control of the computer processing system at a time; first and second thread control components associated with the first and second thread processing components adapted to accept and give up control of the 4 computer processing system on behalf of their corresponding processing thread component; characterised by a yield flag; each of the thread control components having means for checking the flag and giving up control of the computer processing system when the flag is set.
A yield flag which is set to cause a thread to give up control of the processing, takes the control away from the threads themselves and allows the computer system or the user to determine the thread change rate.
i 1.
Preferably the computer processing system is a co-operative threading system whereby the threads themselves control when to give up control of the processing. The invention advantageously allows a preemptive threading virtual machine run within a co-operative threading computer system. A timer component is preferably adapted to set the yield flag after a period of time has elapsed. Such a timer may have a value, set by the user or the computer system,'from which the time starts to count down from. An external timing signal may be input to the timer. When the time reaches zero it sets the yield flag. An initialization component starts the timer component by loading the value into the timer and starting the timer counting down.
The timer component maybe adapted to receive a timing signal from the computer processing system and the timing signal is a real time signal so that the thread switching is constant and independent of the computer system speed.
The yield flag may be checked after every instruction and or after every branch instruction so that the checking machine cycle time is kept to a minimum.
In a second aspect of the invention there is provided a method of implementing pre-emptive threading on a virtual machine, the virtual machine for operating with a computer processing system, the method comprising: processing a first procedure in a virtual machine first thread component using the computer processing system, the first thread component having control of the computer processing system for processing the procedure; setting a yield flag on operation of a timer event; checking the yield flag; halting the processing of the first application procedure on the yield flag being set and initiating processing of a second procedure in a second virtual machine thread using the computer processing system.
In a third aspect of the present invention there is provided a computer program product stored on a computer readable storage medium for, when executed on a computer, executing pre-emptive threading in a virtual machine, the virtual machine for operating with a computer processing system, the method comprising steps of: processing a first procedure in a virtual machine first thread component using the computer processing system, the first thread component having control of the computer processing system for processing the procedure; setting a yield flag on operation of a timer event; checking the yield flag; halting the processing of the first application procedure on the yield flag being set and initiating processing of a second procedure in a second virtual machine thread using the computer processing system.
BRIEF DESCRIPTION OF THE DRAWINGS
In order to promote a fuller understanding of this and other aspects of the present invention, an embodiment will now be described, by way of example only, with reference to the figures in which:
Figure 1 is a schematic drawing of the Java Virtual Machine environment; Figure 2 is a schematic drawing showing the relationship of Java byte code to the JVM; Figure 3 is a schematic drawing of memory space with two threads and their respective stacks; Figure 4 is a schematic drawing showing a known pre-emptive threading JVM; Figure 5 is a schematic showing the pre-emptive threading of the present invention; and Figure 6 is a schematic drawing of the process of pre-emptive threading.
DETAILED DESCRIPTION OF THE EMBODIMENT
A computer 30, such as IBM's ESA/390, has a VM/ESA (Virtual Machine/Enterprise System Architecture) operating system 32 which supports co-operative multithreading but not pre-emptive multithreading (see Figure 5). The operating system includes a single processing 6 component 34 which interacts with a multithreading component 36 to allow the operating system to effectively run several threads simultaneously.
is VM/E5A (Virtual Machine/Enterprise Systems Architecture) is an interactive multiple-access operating system provided by IBM. It is interactive because there is two-way communication between users and VM/ESA. It is a multiple-access system because many people can use a VM/ESA system at the same time. It is the strategic VM operating system for the ESA/390 architecture and offers features equivalent to those of the Virtual Machine/Extended Architecture System Product (MXASAP), which it supersedes.
A VM/ESA JVM 38 runs on top of the operating system 32 and comprises the normal functionality associated with a JVM and, importantly for this embodiment, the threading functionality. The threading functionality comprises thread components 40A,B for processing procedures of a Java application. Each thread component 40A,B breaks down the procedure into its Java byte code instructions and processes each instruction individually. Each thread component 40A,B comprises a control component 42A,B for accepting control from the multithreading component 36 and for passing back control to the multithreading component 36 at a desired time. The threading functionality in the JVM further comprises: a yield flag 44 for indicating to the control components 42A,B when to give up control; and a timer component 46 to set the flag. The timer component 46 has an input from an operating system timer 48 and an input from an initialisation component 50 to set the interval period. When the timer 46 is reset it starts to count a predetermined period using the operating system timer 48 to increment the count. When the timer 46 reaches the Jnterval period it sets the flag 44. The operating system timer 48 in this embodiment is a real time signal that is independent of machine cycle speed. The predetermined period is programmable by changing a variable in JVM memory. In another embodiment an operating system count down function is used whereby the operating system is requested to count down from the predetermined value and signal the timer 46 when zero. The timer 46 uses this signal to set the yield flag.
In operation, the operating system 32, the JVM 38 and the Java byte code application (nct shcq.,n) are loaded into memory on the computer 30. The JVM starts to process the application. For example, the application consists of two procedures running concurrently in two different JVM threads, thread 1 (on thread component 40A) and thread 2 (on thread 7 is component 40B) as indicated in Figure 5. The ivM thread components 40A,B use the underlying operating system threads in the multithreading component 36 which in turn use the single operating system process component 34 to process the instructions of the threads. The first procedure is loaded into the stack by the first JVM thread.
Turning now to Figure 6 at step 60, the JVM control component 42A sets the timer 46 to start timing and also clears the flag 44. At step 52, the first instruction of the procedure is interpreted and processed in the normal way by the thread component 40A using a corresponding operating system thread in the multithreading component 36 and the operating process component 34. After processing one instruction the thread control component 42A checks the yield flag 44, step 64. If the flag 44 has been set by the timer 46 then the thread control component 42A passes control back to the multithreading component 36 so that control may be assigned to the other thread component 40B. If the flag 44 has not been set then the thread continues to process the procedure by fetching the next instruction, interpreting it and processing it in the usual way. The thread cycle goes on until the flag 44 is set by the timer 46 and control passes back to the multithreading component 36.
The multithreading component 36 passes control to the second JVM thread cornponent 40B which clears the flag 44 and timer 46 and begins to process the second procedure. The steps involved are the same as for the first JVY thread. When the flag 44 is set and subsequently checked by the second J%Y, thread component 40B, control passes back to the multithreading component 36. In this embodiment control is passed to the first J1.7M thread component 40A to process the first procedure again but in another example control could be passed on to other JVM threads depending or the program and the number of threads used.
In another embodiment of the invention the check cycle, step 64, occurs less often than every time an instruction is processed. This makes a considerable saving in processor cycle time. The check cycle is set to occur each time a branch instruction is processed. This protects against deadlock as adequately as checking after each instruction since deadlock is normally a result of infinite branching.
In summary then, the Java specification says that the Java threading model must be pre-emptive. On a platform that does not support pre- emptive threads (such as one which supports co-operative threads) it
8 possible to enter a dead lock when an infinite processing loop occurs in one of the threads. This is solved by the use of a timer interrupt in a Java Virtual Machine to simulate pre-emptive threading on a platform whose native model is not pre-emptive. A timer interrupt informs the Java Virtual Machine when to voluntarily pass control from one thread to another.
Although the embodiment is described using a VMESA operating system it should be realised that other operating systems supporting co-operative multithreading would also be suitable. The embodiment has been described in terms of two threads but it will be appreciated that a larger number of threads could be used within the scope of the invention.
9

Claims (11)

1. A virtual machine for operating with a computer processing system, the virtual machine comprising: first and second thread processing components adapted to process respective first and second procedures of computer code using the computer processing system, only one of the thread components having control of the computer processing system at a time; first and second thread control components associated with the first and second thread processing components adapted to accept and give up control of the computer processing system on behalf of their corresponding processing thread component; characterised by a yield flag; each of the thread control components having means for checking the flag and giving up control of the computer processing system when the flag is set.
2. A virtual machine as claimed in claim 1 wherein the computer processing system is a co-operative threading system.
3. A virtual machine as claimed in claim 1 or 2 further comprising a timer component adapted to set the interrupt flag after a period of time has elapsed.
4. A virtual machine as claimed in claim 3 wherein the period of time is programmable
5. A virtual machine as claimed in claim 1,2,3 or 4 further comprising an initialization component adapted to start the timer component timing said period of time.
6. A virtual machine as claimed in claim 3,4 or 5 wherein the timer component is adapted to receive a timing signal from the computer processing system.
7. A virtual machine as claimed in claim 6 wherein the timer component is adapted to receive a real time timing signal.
8. A virtual machine as claimed in any of the preceding claims wherein the means for checking is adapted to check the yield flag after every instruction.
9. A virtual machine as claimed in any one of claims 1 to 8 wherein the means for checking is adapted to check the yield flag after every branch instruction.
10. A method of implementing pre-emptive threading on a virtual machine, the virtual machine for operating with a computer processing system, the method comprising: processing a first procedure in a virtual machine first thread component using the computer processing system, the first thread component having control of the computer processing system for processing the procedure; setting a yield flag on operation of a timer event; checking the yield flag halting the processing of the first application procedure on the yield flag being set and initiating processing of a second procedure in a second virtual machine thread using the computer processing system.
11. A computer program product stored on a computer readable storage medium for, when executed on a computer, executing pre-emptive threading in a virtual rachine, the virtual machine for operating with a computer processing s,.,.stem, the method comprising steps of: processing a first procedure in a virtual machine first thread component using the computer processing system, the first thread component having control of the computer processing system for processing the procedure; setting a yield flag on operation of a timer event; checking the yield flag halting the processing of the first application procedure on the yield flag being set and initiating processing of a second procedure in a second virtual machine thread using the computer processing system.
GB9809279A 1998-04-30 1998-04-30 Pre-emptive threading in a virtual machine Withdrawn GB2336919A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
GB9809279A GB2336919A (en) 1998-04-30 1998-04-30 Pre-emptive threading in a virtual machine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
GB9809279A GB2336919A (en) 1998-04-30 1998-04-30 Pre-emptive threading in a virtual machine

Publications (2)

Publication Number Publication Date
GB9809279D0 GB9809279D0 (en) 1998-07-01
GB2336919A true GB2336919A (en) 1999-11-03

Family

ID=10831273

Family Applications (1)

Application Number Title Priority Date Filing Date
GB9809279A Withdrawn GB2336919A (en) 1998-04-30 1998-04-30 Pre-emptive threading in a virtual machine

Country Status (1)

Country Link
GB (1) GB2336919A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2002048864A2 (en) * 2000-11-20 2002-06-20 Zucotto Wireless, Inc. System registers for an object-oriented processor
US8321849B2 (en) 2007-01-26 2012-11-27 Nvidia Corporation Virtual architecture and instruction set for parallel thread computing
CN103810053A (en) * 2014-02-14 2014-05-21 福建天晴数码有限公司 Method for processing endless loop of game server

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5095427A (en) * 1986-01-14 1992-03-10 Hitachi, Ltd. Dispatch control of virtual machine
EP0617361A2 (en) * 1993-03-26 1994-09-28 Digital Equipment Corporation Scheduling method and apparatus for a communication network
US5632032A (en) * 1994-02-07 1997-05-20 International Business Machines Corporation Cross address space thread control in a multithreaded environment

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5095427A (en) * 1986-01-14 1992-03-10 Hitachi, Ltd. Dispatch control of virtual machine
EP0617361A2 (en) * 1993-03-26 1994-09-28 Digital Equipment Corporation Scheduling method and apparatus for a communication network
US5632032A (en) * 1994-02-07 1997-05-20 International Business Machines Corporation Cross address space thread control in a multithreaded environment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
JavaWorld, "How the Java virtual machine performs thread synchronisation", July 1997 issue *
PC Magazine article by Gregory A. Wolking, "Explore Hotkeys in Windows 95", 11 June 1996 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2002048864A2 (en) * 2000-11-20 2002-06-20 Zucotto Wireless, Inc. System registers for an object-oriented processor
WO2002048864A3 (en) * 2000-11-20 2004-02-26 Zucotto Wireless Inc System registers for an object-oriented processor
US8321849B2 (en) 2007-01-26 2012-11-27 Nvidia Corporation Virtual architecture and instruction set for parallel thread computing
CN103810053A (en) * 2014-02-14 2014-05-21 福建天晴数码有限公司 Method for processing endless loop of game server
CN103810053B (en) * 2014-02-14 2017-06-13 福建天晴数码有限公司 Network game server is absorbed in the processing method of endless loop

Also Published As

Publication number Publication date
GB9809279D0 (en) 1998-07-01

Similar Documents

Publication Publication Date Title
CN100338581C (en) Operating system-independent method and system of determining CPU utilization
US7895597B2 (en) Method, apparatus and computer program product enabling full pre-emptive scheduling of green threads on a virtual machine
RU2263949C2 (en) Translated commands with possible rerun
CN1311351C (en) Programmable event driven yield mechanism which may activate other threads
US20040015627A1 (en) Synchronization of asynchronous emulated interrupts
US5838988A (en) Computer product for precise architectural update in an out-of-order processor
US5615357A (en) System and method for verifying processor performance
US5678032A (en) Method of optimizing the execution of program instuctions by an emulator using a plurality of execution units
Wang et al. COREMU: a scalable and portable parallel full-system emulator
US5958047A (en) Method for precise architectural update in an out-of-order processor
EP2428892A2 (en) Structured exception handling for application-managed thread units
RU2271565C2 (en) Method for memorizing stack operands in register
US7395418B1 (en) Using a transactional execution mechanism to free up processor resources used by a busy-waiting thread
US20020073406A1 (en) Using performance counter profiling to drive compiler optimization
JPH0887420A (en) Method and equipment for control of process thread
US20050005265A1 (en) Method and apparatus for performing adjustable precision exception handling
US8214574B2 (en) Event handling for architectural events at high privilege levels
GB2336919A (en) Pre-emptive threading in a virtual machine
US7895581B2 (en) Profiling collector for computer system
Pfeffer et al. Dynamic real-time reconfiguration on a multithreaded java-microcontroller
Watanabe et al. Exploiting Java instruction/thread level parallelism with horizontal multithreading
US20070156385A1 (en) Runtime selection of code variants in a multiprogram computer hardware emulation system
Schoeberl et al. Non-blocking object copy for real-time garbage collection
Huber Worst-case execution time analysis for real-time Java
Krantz A performance comparison of Clojure and Java

Legal Events

Date Code Title Description
WAP Application withdrawn, taken to be withdrawn or refused ** after publication under section 16(1)