欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

認(rèn)識Java中的Stub與StubQueue

 更新時間:2021年09月09日 17:08:57   作者:HotSpot-Researcher  
StubQueue是用來保存生成的本地代碼的Stub隊列,隊列每一個元素對應(yīng)一個InterpreterCodelet對象,InterpreterCodelet對象繼承自抽象基類Stub,下面我們介紹一下StubQueue類及相關(guān)類Stub、InterpreterCodelet類和CodeletMark類。需要的的下伙伴可以參考下面文字內(nèi)容

在文章開始前先簡單介紹TemplateInterpreter::initialize()函數(shù),在這個函數(shù)中會調(diào)用TemplateTable::initialize()函數(shù)初始化模板表,隨后會使用new關(guān)鍵字初始化定義在AbstractInterpreter類中的_code靜態(tài)屬性,如下:

static StubQueue* _code;

由于TemplateInterpreter繼承自AbstractInterpreter,所以在TemplateInterpreter中初始化的_code屬性其實就是AbstractInterpreter類中定義的_code屬性。

在initialize()函數(shù)中初始化_code變量的代碼如下

// InterpreterCodeSize是在平臺相關(guān)
// 的templateInterpreter_x86.hpp中
// 定義的,64位下是256 * 1024
int code_size = InterpreterCodeSize;
_code = new StubQueue(
                new InterpreterCodeletInterface, 
                code_size, 
                NULL,
                "Interpreter");


StubQueue是用來保存生成的本地代碼的Stub隊列,隊列每一個元素對應(yīng)一個InterpreterCodelet對象,InterpreterCodelet對象繼承自抽象基類Stub,包含了字節(jié)碼對應(yīng)的本地代碼以及一些調(diào)試和輸出信息。下面我們介紹一下StubQueue類及相關(guān)類StubInterpreterCodelet類和CodeletMark類。

1、InterpreterCodelet與Stub類

Stub類的定義如下:

class Stub VALUE_OBJ_CLASS_SPEC { ... };


InterpreterCodelet類繼承自Stub類,具體的定義如下

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實例存儲在StubQueue中,每個InterpreterCodelet實例都代表一段機器指令(包含了字節(jié)碼對應(yīng)的機器指令片段以及一些調(diào)試和輸出信息),如每個字節(jié)碼都有一個InterpreterCodelet實例,所以在解釋執(zhí)行時,如果要執(zhí)行某個字節(jié)碼,則執(zhí)行的就是由InterpreterCodelet實例代表的機器指令片段。

類中定義了3個屬性及一些函數(shù),其內(nèi)存布局如下圖所示。

 

在對齊至CodeEntryAlignment后,緊接著InterpreterCodelet的就是生成的目標(biāo)代碼。

2、StubQueue類

StubQueue是用來保存生成的本地機器指令片段的Stub隊列,隊列每一個元素都是一個InterpreterCodelet實例。

StubQueue類的定義如下:

class StubQueue: public CHeapObj<mtCode> {
 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 <= _buffer_size)
 
  int            _queue_begin;       // the (byte) index of the first queue entry (word-aligned)
  int            _queue_end;         // the (byte) index of the first entry after the queue (word-aligned)
 
  int            _number_of_stubs;   // the number of buffered stubs
 
 
  bool is_contiguous() const {
      return _queue_begin <= _queue_end;
  }
  int index_of(Stub* s) const {
      int i = (address)s - _stub_buffer;
      return i;
  }
  Stub* stub_at(int i) const {
      return (Stub*)(_stub_buffer + i);
  }
  Stub* current_stub() const {
      return stub_at(_queue_end);
  }
 
  // ...
}


這個類的構(gòu)造函數(shù)如下:

StubQueue::StubQueue(
 StubInterface* stub_interface,  // InterpreterCodeletInterface對象
 int            buffer_size,     // 256*1024
 Mutex*         lock,
 const char*    name) : _mutex(lock)
{
  intptr_t     size = round_to(buffer_size, 2*BytesPerWord); // BytesPerWord的值為8
  BufferBlob*  blob = BufferBlob::create(name, size); // 在StubQueue中創(chuàng)建BufferBlob對象
 
  _stub_interface  = stub_interface;
 
  _buffer_size     = blob->content_size();
  _buffer_limit    = blob->content_size();
  _stub_buffer     = blob->content_begin();
 
  _queue_begin     = 0;
  _queue_end       = 0;
  _number_of_stubs = 0;
}


stub_interface用來保存一個InterpreterCodeletInterface類型的實例,InterpreterCodeletInterface類中定義了操作Stub的函數(shù),避免了在Stub中定義虛函數(shù)。每個StubQueue都有一個InterpreterCodeletInterface,可以通過這個來操作StubQueue中存儲的每個Stub實例。

調(diào)用BufferBlob::create()函數(shù)為StubQueue分配內(nèi)存,這里我們需要記住StubQueue用的內(nèi)存是通過BufferBlob分配出來的,也就是BufferBlob其本質(zhì)可能是一個StubQueue。下面就來詳細(xì)介紹下create()函數(shù)。

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是一個指針的寬度,在64位上就是8
 
  {
     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
     blob = new (size) BufferBlob(name, size);
  }
 
  return blob;
}


通過new關(guān)鍵字為BufferBlob分配內(nèi)存,new重載運算符如下:

void* BufferBlob::operator new(size_t s, unsigned size, bool is_critical) throw() {
  void* p = CodeCache::allocate(size, is_critical);
  return p;
}


codeCache中分配內(nèi)存,CodeCache使用的是本地內(nèi)存,有自己的內(nèi)存管理辦法,在后面將會詳細(xì)介紹。

StubQueue的布局結(jié)構(gòu)如下圖所示。

隊列中的InterpreterCodelet表示一個小例程,比如iconst_1對應(yīng)的機器碼,invokedynamic對應(yīng)的機器碼,異常處理對應(yīng)的代碼,方法入口點對應(yīng)的代碼,這些代碼都是一個個InterpreterCodelet。整個解釋器都是由這些小塊代碼例程組成的,每個小塊例程完成解釋器的部分功能,以此實現(xiàn)整個解釋器。

到此這篇關(guān)于認(rèn)識Java中的Stub與StubQueue的文章就介紹到這了,更多相關(guān)Stub與StubQueue內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • springboot實現(xiàn)多模塊項目添加一新模塊

    springboot實現(xiàn)多模塊項目添加一新模塊

    這篇文章主要介紹了springboot實現(xiàn)多模塊項目添加一新模塊,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • Java 和 Scala 如何調(diào)用變參

    Java 和 Scala 如何調(diào)用變參

    這篇文章主要介紹了Java 和 Scala 如何調(diào)用變參,幫助大家更好的理解和學(xué)習(xí)Java與Scala,感興趣的朋友可以了解下
    2020-09-09
  • springBoot定時任務(wù)處理類的實現(xiàn)代碼

    springBoot定時任務(wù)處理類的實現(xiàn)代碼

    這篇文章主要介紹了springBoot定時任務(wù)處理類,需要的朋友可以參考下
    2018-06-06
  • Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法

    Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法

    這篇文章主要介紹了Mybatis-Plus-AutoGenerator 最詳細(xì)使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Java Runtime類詳解_動力節(jié)點Java學(xué)院整理

    Java Runtime類詳解_動力節(jié)點Java學(xué)院整理

    Runtime類封裝了運行時的環(huán)境。每個 Java 應(yīng)用程序都有一個 Runtime 類實例,使應(yīng)用程序能夠與其運行的環(huán)境相連接。下面通過本文給大家分享Java Runtime類詳解,需要的朋友參考下吧
    2017-04-04
  • Mybatis動態(tài)sql中@Param使用詳解

    Mybatis動態(tài)sql中@Param使用詳解

    這篇文章主要介紹了Mybatis動態(tài)sql中@Param使用詳解,當(dāng)方法的參數(shù)為非自定義pojo類型,且使用了動態(tài)sql,那么就需要在參數(shù)前加上@Param注解,需要的朋友可以參考下
    2023-10-10
  • springboot使用dubbo和zookeeper代碼實例

    springboot使用dubbo和zookeeper代碼實例

    這篇文章主要介紹了springboot使用dubbo和zookeeper代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-11-11
  • javaweb servlet生成簡單驗證碼

    javaweb servlet生成簡單驗證碼

    這篇文章主要為大家詳細(xì)介紹了javaweb servlet生成簡單驗證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • 關(guān)于Springboot | @RequestBody 接收到的參數(shù)對象屬性為空的問題

    關(guān)于Springboot | @RequestBody 接收到的參數(shù)對象屬性為空的問題

    這篇文章主要介紹了關(guān)于Springboot | @RequestBody 接收到的參數(shù)對象屬性為空的問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-03-03
  • 詳解在SpringBoot中使用MongoDb做單元測試的代碼

    詳解在SpringBoot中使用MongoDb做單元測試的代碼

    這篇文章主要介紹了詳解在SpringBoot中使用MongoDb做單元測試的代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評論