In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "the usage of Stub class and StubQueue class in Java". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Catalogue
1. InterpreterCodelet and Stub classes
2. StubQueue class
At the beginning of the article, the TemplateInterpreter::initialize () function is briefly introduced, in which the TemplateTable::initialize () function is called to initialize the template table, and then the _ code static property defined in the AbstractInterpreter class is initialized using the new keyword, as follows:
Static StubQueue* _ code
Because TemplateInterpreter inherits from AbstractInterpreter, the _ code attribute initialized in TemplateInterpreter is actually the _ code property defined in the AbstractInterpreter class.
The code to initialize the _ code variable in the initialize () function is as follows:
/ / InterpreterCodeSize is defined in the platform-related / / templateInterpreter_x86.hpp. Under 64-bit, it is 256 * 1024int code_size = InterpreterCodeSize;_code = new StubQueue (new InterpreterCodeletInterface, code_size, NULL, "Interpreter")
StubQueue is a Stub queue used to save the generated local code. Each element of the queue corresponds to an InterpreterCodelet object. The InterpreterCodelet object inherits from the abstract base class Stub and contains the local code corresponding to the bytecode as well as some debugging and output information. Let's take a look at the StubQueue class and its related classes Stub, InterpreterCodelet, and CodeletMark.
1. InterpreterCodelet and Stub classes
The Stub class is defined as follows:
Class Stub VALUE_OBJ_CLASS_SPEC {...}
The InterpreterCodelet class inherits from the Stub class and is defined as follows:
Class InterpreterCodelet: public Stub {private: int _ size; / / the size in bytes const char* _ description; / / a description of the codelet, for debugging & printing Bytecodes::Code _ bytecode; / / associated bytecode if any public: / / Code info address code_begin () const {return (address) this + round_to (sizeof (InterpreterCodelet), CodeEntryAlignment);} address code_end () const {return (address) this + size () } int size () const {return _ size;} / /. Int code_size () const {return code_end ()-code_begin ();} / /.}
InterpreterCodelet instances are stored in StubQueue, and each InterpreterCodelet instance represents a piece of machine instruction (containing the machine instruction fragment corresponding to the bytecode as well as some debugging and output information). For example, each bytecode has an InterpreterCodelet instance, so if a bytecode is to be executed, the machine instruction fragment represented by the InterpreterCodelet instance is executed.
Three properties and some functions are defined in the class, and their memory layout is shown in the following figure.
After aligning to CodeEntryAlignment, InterpreterCodelet is followed by the generated object code.
2. StubQueue class
StubQueue is a Stub queue used to hold fragments of generated local machine instructions, and each element of the queue is an instance of InterpreterCodelet.
The StubQueue class is defined as follows:
Class StubQueue: public CHeapObj {private: StubInterface* _ stub_interface; / / the interface prototype address _ stub_buffer; / / where all stubs are stored int _ buffer_size; / / the buffer size in bytes int _ buffer_limit; / / the (byte) index of the actual buffer limit (_ buffer_limit content_size (); _ stub_buffer = blob- > content_begin () _ queue_begin = 0; _ queue_end = 0; _ number_of_stubs = 0;}
Stub_interface is used to hold an instance of the InterpreterCodeletInterface type, and the InterpreterCodeletInterface class defines functions that operate on Stub, avoiding defining virtual functions in Stub. Each StubQueue has an InterpreterCodeletInterface that can be used to manipulate each Stub instance stored in the StubQueue.
Call the BufferBlob::create () function to allocate memory for StubQueue, and here we need to remember that the memory used by StubQueue is allocated through BufferBlob, that is, BufferBlob may be essentially a StubQueue. Let's take a detailed look at the create () function.
BufferBlob* BufferBlob::create (const char* name, int buffer_size) {/ /. BufferBlob* blob = NULL; unsigned int size = sizeof (BufferBlob); / / align the size to CodeEntryAlignment size = align_code_offset (size); size + = round_to (buffer_size, oopSize); / / oopSize is the width of a pointer, which is 8 {MutexLockerEx mu (CodeCache_lock, Mutex::_no_safepoint_check_flag) on 64 bits; blob = new (size) BufferBlob (name, size);} return blob;}
Use the new keyword to allocate memory for BufferBlob, and the new overload operator is as follows:
Void* BufferBlob::operator new (size_t s, unsigned size, bool is_critical) throw () {void* p = CodeCache::allocate (size, is_critical); return p;}
Allocating memory from codeCache, CodeCache uses local memory and has its own memory management method, which will be described in more detail later.
The layout structure of StubQueue is shown in the following figure.
The InterpreterCodelet in the queue represents a small routine, such as the machine code corresponding to iconst_1, the machine code corresponding to invokedynamic, the code corresponding to exception handling, and the code corresponding to the method entry point, all of which are InterpreterCodelet. The whole interpreter is composed of these small code routines, and each small routine completes part of the function of the interpreter, thus realizing the whole interpreter.
This is the end of the introduction to "the use of Stub class and StubQueue class in Java". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.