Summary of the invention
The invention provides a kind of kaffe dummy machine system and its implementation, this system can have improvement greatly at aspects such as transplantability, retractility and high-level efficiency, can be used in more demand occasions.
A kind of kaffe dummy machine system provided by the invention comprises:
The class manager is used for loading classes and to the initialization of class;
The bytecode validator is used to verify bytecode, guarantees the correctness of class file format;
The Kaffe virtual machine is carried out engine, comprises interpreter and just-time compiler, and compiler is used for bytecode compile cost ground machine code, and interpreter is used for that the bytecode through compiling is construed to instruction to be carried out;
The system call subsystem, the system call that is used to call local core library;
The thread subsystem is used for management thread and creates, deletes;
Storage management subsystem is used for garbage reclamation, new object/class/data allocations;
The native method interface subsystem is used for the various interface support.
According to a further aspect in the invention, the present invention also provides a kind of implementation method of kaffe virtual machine, comprises the steps:
(1) default value of acquisition virtual machine environment parameter;
(2) processing command capable in the parameter that is provided with of user;
(3) carry out initialization, storage allocation for virtual machine;
(4) the main classes name that provides in order line according to the user is sought main classes, it is loaded, again to the link and the initialization of load classes;
(5) again the bytecode of compiling the principal function method behind the pool is explained one by one.
Further, the kaffe virtual machine adopts the 0S20 real time operating system, and the size that the operation of task is based on priority in 0S20 is shared resource; The task that priority level is different adopts the mode of seizing to dispatch by the scheduling kernel, and the task that priority level is identical then adopts the mode of round-robin to dispatch.
Further, by Semaphore Mechanism control multitask between the visit of a shared resource and the task synchronously, utilize message queue as a kind of data communication mode between task, a message queue has the certain amount of message buffer zone in 0S20.
Further, described message queue separated into two parts, a part is current otiose message buffer-idle queues; Another part is that message has been sent but also do not had received message buffer-transmit queue, a buffer zone or be empty, carrying message does not also discharge, just circulating between these two formations in all message buffers, makes the total system trouble-free operation by semaphore and message queue.
From technique scheme as can be seen, because the embodiment of the invention is positioned at the set-top box middleware layer of hierarchical design, application program and the bottom layer driving that depends on hardware are separated, made application program have better transplantability, the upgrading of software provides convenience for future.Kaffe has the relevant local library of the platform of oneself, is taken up space and is easy to and transplant by reducing system, and Mu Diku both can be configured to also to can be configured to dynamically static state.Part is realized in this locality that the corresponding Java standard of these libraries class libraries is relevant with system, as I/O operation, mathematical function, figure support, network support etc.And this system's employing modularized program designs, kernel is little, be easy to cutting, thereby has guaranteed its scalability and high-level efficiency, applicable to multi-platform.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.
The embodiment of the invention provides a kind of implementation method of kaffe dummy machine system, there is the relevant local library of the platform of oneself in this system, part is realized in this locality that the corresponding Java standard of these libraries class libraries is relevant with system, as I/O operation, mathematical function, figure support, network support etc.This system's employing modularized program designs, kernel is little, be easy to cutting, and scalability and high-level efficiency are good, applicable to multi-platform.Below be elaborated respectively.
Based on the middleware implementation of set-top box as shown in Figure 1, it is divided into four levels: operating system layer, hardware driving layer, middleware layer and application layer.Operating system layer adopts real-time multi-task operating system; The bottom layer driving layer mainly provides the driver of operating system inside and each hardware device; Application layer comprises the application of this machine storage and downloads; Middleware is separated application program and the bottom layer driving that depends on hardware, makes application program have better transplantability, and the upgrading of software provides convenience for future.
From bottom to top each layer carried out brief introduction:
The hardware driving layer: this layer is the hardware environment of set-top box, and the driver of each hardware device is realized control to hardware by the read-write to the hardware device register.Audio/video decoding driving, demultiplexing and tables of data extraction, Tuner tune drive, storage drive, condition receive driving and screen display driving etc. and all realize at this one deck.The device driver hardware equipment is for individual abridged table and JavalTVAPI provide support.
Operating system layer: this layer comprises the 0S20 real-time oss device driver of unifying.The 0S20 that this programme adopted is a kind of high efficiency real-time multi-task operating system, be applicable to all ST20 series processors, task management, memory management, message queue service, semaphore service, clock and functions such as timer management, interrupt management are provided.0S20 is that the virtual machine of Java platform (CDC) and the operation of class libraries provide system-level support.
Middleware layer: middleware system has characteristics such as stability, opening, interactivity, upgradability, make that the exploitation of application program can be based on the unified interface that is provided by middleware, application software engineering teacher can understand the concrete structure of hardware platform, not only make hardware and software development parallel, shorten the construction cycle, also improved the portability of application software on different hardware platforms and operating system greatly.This layer comprises Java platform (CDC) and java application standard interface, and it provides complete Java environment for the operation of java application.Wherein the java application standard interface comprises individual abridged table and JavaTVApl.
Application layer: application layer is one of major part of software development, is positioned at the superiors of software configuration, is the DLL (dynamic link library) of graphic presentation with user interface.The abundant Java application software of standard interface exploitation that this layer utilizes the middle layer to provide provides interactive TV program to the user.
Based on the consideration of system's portability and scalability aspect, the Kaffe virtual machine adopts modular program design.As shown in Figure 2: it is made up of a plurality of independent subsystem:
(1) class manager is responsible for loading classes and to the initialization of class etc.;
(2) bytecode validator is verified bytecode, guarantees the correctness of class file format;
(3) Kaffe virtual machine execution engine comprises interpreter and just-time compiler, and just-time compiler is responsible for elder generation using bytecode compile cost ground machine code, and interpreter is responsible for a ground is carried out being construed to instruct through the bytecode that compiles.Carry out local machine code, can reduce the workload of translation,, raise the efficiency so that abdicate CPu time program logic;
(4) system call subsystem, the system call of calling local core library;
(5) thread subsystem, management thread establishment, deletion etc.;
6) storage management subsystem is responsible for garbage reclamation, new object/class/data allocations etc.;
(7) native method interface subsystem is responsible for the various interface support, supports native language support etc. as JUI.
Kaffe has the relevant local library of the platform of oneself, is taken up space and is easy to and transplant by reducing system, and local library both can be configured to also to can be configured to dynamically static state.Part is realized in this locality that the corresponding Java standard of these libraries class libraries is relevant with system, as I/O operation, mathematical function, figure support, network support etc.The Kaffe virtual machine realizes that with the C language all from the main function, Kaffe is no exception in the execution of any C programmer.
The program flow diagram of main function when accompanying drawing 3 is the kaffe operation comprises: comprise the steps: that (1) obtains the default value of virtual machine environment parameter; (2) processing command capable in the parameter that is provided with of user; (3) carry out initialization, storage allocation for virtual machine; (4) the main classes name that provides in order line according to the user is sought main classes, it is loaded, again to the link and the initialization of load classes; (5) again the bytecode of compiling the principal function method behind the pool is explained one by one.
It also is the flowchart of whole virtual machine, and the specific procedure implementation is as follows:
1. at first obtain the default value of virtual machine environment parameter, the function that obtains this default value is by function JNI_GetDefaultJavaVMInitArgs (﹠amp; Vmargs) realize that this function can copy structure Kaffe_JavaVMInitArgs among the vmargs to.
2. processing command capable in the parameter that is provided with of user, this function is by function static int options (char
*Argv) finish.This function parameters is main (argc, the argy) argv in, the just part of Kaffe back during the utility command row.Its rreturn value is a shaping amount, represents the parameter amount that this function is handled.
3. carry out initialization, storage allocation for virtual machine.This function is passed through call function jintJNI_CreateJavaVM (JavaVM in the main function
*Vm, JNIEnv
*Env, JavaVMInitArgs
*Args) realize.Parameter vmags is by the virtual machine parameter sets of initialize in this function, and this function will point to JVM after the generation work of finishing virtual machine pointer leaves among the vm.The work that virtual machine generates mainly is the application internal memory, then parameter is wherein carried out default setting.
4. the main classes name that provides in order line according to the user is sought main classes and with its loading, link, initialization.
This is the emphasis of whole virtual machine implementation.In the main function, realize by calling FindClass ().After finding class, call LoadClass () function and come load classes, call ProcessClass () again and finish the link and the initialization of load classes.After loading, link, initialization are all finished, again the bytecode of compiling the main method behind the pool is explained one by one.
Task (Task) is the main ingredient of real time operating system, the control thread that task is exactly an independent operating, as long as storage space allows, an application program can be divided into any a plurality of task.This kaffe dummy machine system adopts the 0S20 real time operating system, and the size that the operation of task is based on priority in 0S20 is shared resource.The task that priority level is different adopts the mode of seizing to dispatch by the scheduling kernel, and the task that priority level is identical then adopts the mode of round-robin to dispatch.The 0S20 kernel has used the dispatching algorithm of a multitask, guarantees that the task of current operation has the highest priority.
By semaphore (Semaphore) mechanism control multitask between the visit of a shared resource and the task synchronously.Utilize message queue (MessageQueue) as a kind of data communication mode between task.A message queue has certain amount of message buffer zone (the number size determines) when initialization in 0S20.Whole formation separated into two parts, a part are current otiose message buffer-idle queues; Another part is that message has been sent but also do not had received message buffer-transmit queue.A buffer zone or be empty, otherwise carrying message does not also discharge, and just circulate between these two formations in all message buffers.Make the total system trouble-free operation by semaphore and message queue.
One of ordinary skill in the art will appreciate that all or part of step in the whole bag of tricks of the foregoing description is to instruct relevant hardware to finish by program, this program can be stored in the computer-readable recording medium, storage medium can comprise: ROM (read-only memory) (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), disk or CD etc.
More than the implementation method of a kind of kaffe dummy machine system that the embodiment of the invention provided is described in detail, for one of ordinary skill in the art, according to thought of the present invention, part in specific embodiments and applications all can change, in sum, this description should not be construed as limitation of the present invention.