• 沒有找到結果。

Hardware Native Interface

在文檔中 多執行緒Java處理器設計 (頁 27-30)

第三章 Multicore Multithreading Java 處理器架構

3.1. Hardware Native Interface

Java 平台的 native method 大多數以其他語言或組合語言的 library 實做,透過呼叫 這些 library 完成工作並且回傳數值。為了使 Java Thread Class 能正確地操作 ICCU、Thead Manager Unit 或者其他加速電路,在不修改原有 Java 應用程式情況下,我們加入 Hardware Native Interface[2]的設計,這個介面由 DSRU 觸發,使得 native method 的執行 介面達到一致性,如果開發者要為某一個 native method 新增一個等價電路時,便可以簡 單地連接 Hardware Native Interface 的輸出輸入訊號。

Dynamic Symbol Resolution Unit

Method Area Controller

cls_id mthd_id

Bytecode Execution

Engine

RISC-code Hardware Accelerator

native_HW_ID native_HW_en native_HW_cmplt

java_bytecode interrupt_func_DR

interrupt_req_DR interrupt_cmplt

IPC Register file

PLB

argument

圖 12 JAIP 調用的 3 種介面

(1) Bytecode Execution Engine (2) RISC-core (3) Hardware Accelerator

圖 12 說明 JAIP 處理器內 2 種 natvie method 的實作方式:其一是啟動 interrupt 通 知 RISC-core,RISC-core 提供對應的 native C function 來完成工作,執行過程中由 RISC-code 讀取 JAIP 的 stack memory 頂端 data words;第二種方式是 Hardware Native Interface,當 DSRU 解析過程中發現即將呼叫一個 native method,且該 native method ID

18

對應到某個 JAIP 處理器支援的 Hardware Accelerator,則啟動對應的電路、傳入 method 參數並執行工作、把回傳值寫到 stack memory 頂端,當其對應的電路工作結束時,發送 完成訊號到 DSRU,此時完成 native method invocation。此設計的好處是可降低 native method 執行時間。

圖 13 在 DSRU 中呼叫 Hardware Native Interface 的 state diagram

在我們的設計下當 current thread 呼叫 native method 會執行 invokevirtual、invokestatic 等指令 ,當 Decode Stage 解析發現要執行這些指令時便會啟動 Dynamic Symbol Resolution Unit(DSRU),此時 DSRU 狀態從 Idle 到 Get_XRT_idx_from_CSCB(如圖 13),

同時將 operand bytes 及 control flags 從 Decode stage 傳給 DSRU,DSRU 之後根據 decode stage 給的 control flags 來決定工作內容,如果發現是要呼叫 method 的動作,則 DSRU

Adjusting return

XRT: Cross-reference table MT: method

IF: interface

DRC: Dynamic Res. Ctrlr FLD: field

ID matches head of list

ID does not match head of list matched

still searching?

class not loaded

Execution of a

static/native/clinit method, new object,

or field access Wait for RISC

response

Wait for HW response 2 cycles

19

從 Cross Reference Table 找到對應的 method info list,逐一檢查每個 method info 的 cls_id、mthd_id、native_flag (圖 14)。當 DSRU 搜尋到正確的 class ID 與 method ID 時,

其狀態便進入到 Check_FLD_or_MT_info,檢查目前這個 method 相關資料是否已被載入 到 Method Area Circular Buffer 與 Class Symbol Table Circular Buffer,如果沒有則先進入 DynamicClass_Loading_Parsing 狀態,啟動 Class parser 把 class data 與 method bytecode 分別載入 Class Symbol Table Circular Buffer 與 Method Area Circular Buffer 之後,再檢查 native_flag 的值,決定要下個狀態是 MACB_CSCB_Loading 或是 Native_invoke。如果呼 叫的 method bytecode 已被載入到 Method Area Circular Buffer,則不需啟動 Class Parser,

直接判斷 native_flag 決定下個狀態是 Native_invoke 或是 MACB_CSCB_Loading。由於 在此我們舉例 current thread 呼叫 native method,因此,native_flag=1,DSRU 下個狀態 進入 Native_invoke。

Class Symbol Table Circular Buffer

Entry 0 Entry 1 (2) (4) pointer

.

Cross Reference Table

pointer Class ID

Class ID Method ID .

. .

0xFFFF Class ID

(1) Class ID Method ID .

. .

pointer Class ID

Class ID Method ID .

#bytes for return (4)

Argument size

圖 14 method info list 訪問過程與 method info 格式

native_hardware_flag(圖 14)被用來判斷此 native method 是由 RISC-core 實作與否。

如果其值為 0,表示這個 method 以 RISC-core 實作 interrupt service routine,此時 mthd_id

20

表示 interrupt service routine ID 編號,且 DSRU 下個狀態進入 Invoke_SW_native_code;

如果其值為 1,表示這個 method 是由 hardwired 電路或加速器實作,此時把 method info 的 method ID 欄位寫入 native_HW_ID 並且 DSRU 下個狀態進入 Invoke_HW_logic。當 DSRU 狀態為 Invoke_HW_logic 時啟動 Hardware Native Interface,把 native_HW_en、

native_HW_ID 這 2 個 Hardware Native Interface 輸出訊號連接個別加速電路模組內。

以圖 10 為例,當 main thread 呼叫 t1.start()或者 t2.start()時會啟動 DSRU,如上一段 描述當 DSRU 到 Cross Reference Table 讀取 Thread.start()的 method info 時發現 native_flag 與 native_hardware_flag 的值皆為 1,因此 DSRU 下個狀態進入 Invoke_HW_logic。根據 圖 12,Hardware Native Interface 的 native_HW_en、native_HW_ID 兩條訊號連接到 ICCU,當 DSRU 狀態為 Invoke_HW_logic,如果 native_HW_en 等於 1 則透過 Hardware Native Interface 觸發 ICCU 執行產生 new thread 的動作,ICCU (圖 19)詳細步驟即將在 section 3-3 描述。當 ICCU 完成產生 new thread 工作之後,native_HW_cmplt 等於 1 且 native_HW_en 等 於 0 , 此 時 DSRU 的 狀 態 從 Invoke_HW_logic 轉 到 Adjusting_return_stack,把 2-level Java Runtime Stack 回復到呼叫 method 之前的狀態,

最後完成呼叫 start method 的工作。

在文檔中 多執行緒Java處理器設計 (頁 27-30)