2. BASIC JAVA EXECUTION
Basic execution of an application written in the Java programming language begins with the Java source code. The Java source code files (.java files) are translated by a Java compiler into Java byte codes, which are then placed
into. class files. The byte codes define the instruction set for the JVM which actually executes the user’s application program.
2.1. Java Virtual Machine(JVM)
The Java Virtual Machine(JVM) executes the Java program’s byte codes [Lindholm and Yellin 1997; Meyer and Downing 1997]. The JVM is said to bevirtualsince, in general, it is implemented in software on an existing hardware platform. The JVM must be implemented on the target platform before any compiled Java programs can be executed on that platform. The ability to implement the JVM on various platforms is what makes Java portable. The JVM provides the interface between compiled Java programs and any target hardware platform.Traditionally, the JVM executes the Java byte codes by interpreting a stream of byte codes as a sequence of instructions. One stream of byte codes exists for each method in the class. They are interpreted and executed when a method is invoked during the execution of the program. Each of the JVM’s stack-based instructions consists of a one-byteopcodeimmediately followed by zero or more operands. The instructions operate onbyte, short, integer,long,float,double,char,object, andreturn addressdata types. The JVM’s instruction set defines 200 standard opcodes, 25quick variationsof some opcodes (to support efficient dynamic binding), and three reserved opcodes. The opcodes dictate to the JVM what action to perform. Operands provide additional information, if needed, for the JVM to execute the action. Since byte code instructions operate primarily on a stack, all operands must be pushed on the stack before they can be used. The JVM can be divided into the five basic components shown in Figure 1. Each of the registers, stack, garbage-collected heap, methods area, and execution engine components must be implemented in some form in every JVM. The registerscomponent includes aprogram counterand three other registers used to manage the stack.Since most of the bytecode instructions operate on the stack, only a few registers are needed. The bytecodes are stored in the methods area. Theprogram counterpoints to the next byte in themethods areato be executed by the JVM. Parameters for bytecode instructions, as well as results from the execution of bytecode instructions,are stored in thestack. The stack passes parameters and return values to and from the methods. It is also used to maintain the state of each method invocation, which is referred to as the stack frame. The optop,frame, andvarsregisters manage the stack frame. Since the JVM is a stack-based machine,all operations on data must occur through the stack. Data is pushed onto the stack from constant pools stored in the methods area and from the local variables section of the stack. Thestack frame is divided into three sections. The first is the local variablessection which contains all of the local variables being utilized by the current method invocation. Thevarsregister points to this section of the stack frame. The second section of the stack frame is the execution environment, which maintains the stack operations. The frame register points to this section. The final section is theoperand stack. This section is utilized by the bytecode instructions for storing parameters and temporary data for expression evaluations. Theoptopregister points to the top of the operand stack. It should be noted that the operand stackis always the topmost stack section. Therefore, theoptopregister always points to the top of the entire stack. While instructions obtain their operands from the top of the stack, the JVM requires random access into the stack to support instructions likeiload, which loads an integer from the local variables section onto the operand stack, oristore, which pops an integer from the top of the operand stack and stores it in the local variables section. Memory is dynamically allocated to executing programs from the garbagecollected heapusing thenewoperator. The JVM specification requires that any space allocated for a new object be preinitialized to zeroes. Java does not permit the user to explicitly free allocated memory. Instead, the garbage collection process monitors existing objects on the heap and periodically marks those that are no longer being used by the currently executing Java program. Marked objects are then returned to the pool of available memory. Implementation details of the garbage collection mechanism are discussed further in Section 2.2. that executes the bytecodes of the Java methods. This “virtual” processor can be implemented as an interpreter, a compiler,or a Java-specific processor. Interpreters and compilers are software implementations of the JVM while Java processors implement the JVM directly in hardware.The execution engine interacts with the methods area to retrieve the bytecodes for execution. Various implementations of the Java execution engine are described in subsequent sections.
2 java การดำเนินการดำเนิน
พื้นฐานพื้นฐานของการประยุกต์ใช้การเขียนในการเขียนโปรแกรมภาษาจาวาเริ่มต้นด้วยซอร์สโค้ดจาวา ไฟล์รหัสต้นฉบับจาวา (. ไฟล์ java) มีการแปลโดยรวบรวม java เป็นรหัสไบต์จาวาที่มีอยู่แล้วใน
ไฟล์ชั้น รหัสไบต์กำหนดชุดคำสั่งสำหรับ JVM ที่จริงรันโปรแกรมประยุกต์ของผู้ใช้.
2.1จาวาเครื่องเสมือน (JVM)
เครื่องเสมือนจาวา (JVM) รันรหัสไบต์โปรแกรม java ของ [Lindholm และสะใจ 1997; เมเยอร์และดาวนิง 1997] jvm ที่ทำงานบอกว่าจะ bevirtualsince โดยทั่วไปจะมีการดำเนินการในซอฟต์แวร์บนแพลตฟอร์มฮาร์ดแวร์ที่มีอยู่ jvm ที่ทำงานอยู่จะต้องดำเนินการบนแพลตฟอร์มเป้าหมายก่อนที่โปรแกรมจาวารวบรวมใด ๆ ที่สามารถดำเนินการในแพลตฟอร์มที่ความสามารถในการใช้ JVM บนแพลตฟอร์มต่างๆเป็นสิ่งที่ทำให้จาวาแบบพกพา JVM มีอินเตอร์เฟซระหว่างโปรแกรมจาวารวบรวมและฮาร์ดแวร์ใด platform.traditionally เป้าหมาย JVM รันรหัสไบต์ java โดยการตีความกระแสของรหัสไบต์เป็นลำดับของคำสั่ง หนึ่งกระแสของรหัสไบต์ที่มีอยู่สำหรับแต่ละวิธีในชั้นเรียนพวกเขาจะถูกตีความและดำเนินการเมื่อวิธีการถูกเรียกในระหว่างการทำงานของโปรแกรม แต่ละคำแนะนำ JVM ของสแต็คที่ใช้ประกอบการปฏิบัติตามหนึ่ง byteopcodeimmediately โดยศูนย์หรือมากกว่าตัวถูกดำเนินการ คำแนะนำการใช้งาน onbyte สั้นจำนวนเต็มยาวลอยคู่ถ่านวัตถุ, andreturn addressdata ประเภท ชุดคำสั่ง JVM ที่กำหนด 200 opcodes มาตรฐาน25quick variationsof opcodes บางคน (ที่จะสนับสนุนแบบไดนามิกที่มีประสิทธิภาพมีผลผูกพัน) และสาม opcodes จอง opcodes กำหนดให้ JVM ว่าการกระทำที่จะดำเนินการ ตัวถูกดำเนินการให้ข้อมูลเพิ่มเติมถ้าจำเป็นสำหรับ JVM ที่จะดำเนินการการกระทำ ตั้งแต่คำแนะนำรหัสไบต์ทำงานหลักในกองตัวถูกดำเนินการทั้งหมดจะต้องได้รับการผลักดันในสแตกก่อนที่พวกเขาสามารถใช้jvm ที่ทำงานสามารถแบ่งออกเป็นห้าองค์ประกอบพื้นฐานที่แสดงในรูปที่ 1 แต่ละรีจิส, กอง, กองขยะที่เก็บรวบรวมพื้นที่วิธีการและชิ้นส่วนเครื่องยนต์ดำเนินการจะต้องดำเนินการในรูปแบบบางอย่างในทุก JVM registerscomponent รวมถึง aprogram counterand ลงทะเบียนในสามอื่น ๆ ที่ใช้ในการจัดการ stack.since ที่สุดของคำแนะนำ bytecode ทำงานในกองที่เพียงไม่กี่ลงทะเบียนมีความจำเป็น bytecodes จะถูกเก็บไว้ในพื้นที่วิธีการ counterpoints theprogram จะไบต์ต่อไปใน themethods areato ได้รับการดำเนินการโดย JVM พารามิเตอร์สำหรับคำแนะนำ bytecode เป็นผลลัพธ์จากการทำงานของคำสั่ง bytecode จะถูกเก็บไว้ใน thestack สแต็คที่ส่งผ่านพารามิเตอร์และค่าตอบแทนและจากวิธีการที่ก็ยังใช้ในการรักษาสถานะของแต่ละวิธีการภาวนาซึ่งจะเรียกว่าเป็นกรอบสแต็ค optop, กรอบ, กรอบ andvarsregisters จัดการกอง ตั้งแต่ JVM เป็นเครื่องที่สแต็คที่ใช้การดำเนินการทั้งหมดอยู่กับข้อมูลที่จะต้องเกิดขึ้นผ่านกอง ข้อมูลจะถูกผลักลงบนสแต็คจากสระว่ายน้ำคงที่ที่เก็บไว้ในพื้นที่วิธีการและจากส่วนตัวแปรท้องถิ่นของสแต็คกรอบ thestack แบ่งออกเป็นสามส่วน แรกเป็น variablessection ท้องถิ่นซึ่งมีทั้งหมดของตัวแปรท้องถิ่นที่ถูกนำมาใช้โดยวิธีการภาวนาในปัจจุบัน จุด thevarsregister ไปยังส่วนของกรอบกองนี้ ส่วนที่สองของกรอบสแต็คที่เป็นสภาพแวดล้อมการดำเนินการซึ่งรักษาการดำเนินงานของสแต็ค จุดกรอบการลงทะเบียนในส่วนนี้ส่วนสุดท้ายเป็นกอง theoperand ส่วนนี้ถูกนำมาใช้ตามคำแนะนำ bytecode สำหรับพารามิเตอร์การจัดเก็บและข้อมูลชั่วคราวสำหรับการประเมินผลการแสดงออก theoptopregister ชี้ไปที่ด้านบนสุดของกองตัวถูกดำเนินการ มันควรจะตั้งข้อสังเกตว่าตัวถูกดำเนินการ stackis เสมอส่วนกองสูงสุด ดังนั้น theoptopregister เสมอชี้ไปที่ด้านบนของทั้งกองในขณะที่คำแนะนำได้ถูกดำเนินการของพวกเขาจากด้านบนของสแต็ค, JVM ต้องมีการเข้าถึงแบบสุ่มเข้าไปในกองเพื่อสนับสนุนคำแนะนำ likeiload ที่โหลดจำนวนเต็มจากส่วนตัวแปรท้องถิ่นเข้าสู่สแตกตัวถูกดำเนินการที่ oristore ซึ่งปรากฏจำนวนเต็มจากด้านบนของ สแต็คที่ถูกดำเนินการและเก็บไว้ในส่วนของตัวแปรท้องถิ่นหน่วยความจำที่จัดสรรแบบไดนามิกที่จะรันโปรแกรมจาก thenewoperator heapusing garbagecollected ข้อกำหนด JVM กำหนดว่าพื้นที่ใดที่จัดสรรสำหรับวัตถุใหม่ที่จะได้รับการ preinitialized เลขศูนย์ java ไม่อนุญาตให้ผู้ใช้ในการจัดสรรหน่วยความจำอย่างชัดเจนฟรี แทนขั้นตอนการเก็บขยะตรวจสอบวัตถุที่มีอยู่ในกองและระยะเครื่องหมายเหล่านั้นที่ไม่ได้ถูกใช้โดยโปรแกรม java ที่กำลังดำเนินการ วัตถุที่ทำเครื่องหมายไว้จะถูกส่งกลับไปยังสระว่ายน้ำของหน่วยความจำที่มีอยู่ รายละเอียดการดำเนินงานของกลไกการเก็บขยะจะกล่าวถึงต่อไปในส่วน 2.2 ที่รัน bytecodes วิธี javaหน่วยประมวลผลนี้ "เสมือน" สามารถดำเนินการเป็นล่ามคอมไพเลอร์หรือหน่วยประมวลผลจาวาเฉพาะ แปลและคอมไพเลอร์จะมีการใช้งานซอฟต์แวร์ของ JVM ในขณะที่การประมวลผลจาวาใช้ JVM โดยตรงในเครื่องยนต์ hardware.the มีปฏิสัมพันธ์กับพื้นที่วิธีการที่จะดึง bytecodes สำหรับการดำเนินการการใช้งานต่างๆของเครื่องยนต์ java อธิบายไว้ในส่วนต่อมา
การแปล กรุณารอสักครู่..
