Concurrent Rubi
contributed by <green0413
>, <shouchengH
>, <SarahYuHanCheng
>, <eesuserp
>
預期進度表:
11/25 完成expr,function,(while,for)剛剛說的事
11/26、27 定義完rubi的BNF ( prefix )
預期目標
- 探討編譯器設計,以 DynASM 為例,解說 Rubi 運作原理,並提出 code refactoring 與效能改善機制
- 實做 concurrency 語法支援,不必跟 Ruby 相容
- 依據 prog 的程式,熟悉 Rubi 語法,著手設計類似 A09: jit-compiler 裡頭整合性的 benchmark suite,提出改善內建 benchmark suite 效能的機制,並且要能夠充分解釋行為,需要一併透過 gnuplot 自動產生效能分析圖表
- 對 Rubi 程式語言進行擴充,使其能夠支援 concurrency / parallelism。需要有程式語言的規格描述並且驗證。
中英文字間請以空白隔開
課程助教
產出
資料閱讀
深入探索 Linux 核心架構
- 特權等級
- intel IA-32 系架構使用 4 種特權等級構成。以下圖為例,越內環能夠存取越多功能,外環則越少。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Linux 只使用兩種模式: Kernel mode 和 User mode。兩種模式的關鍵差別在對於高於
TASK_SIZE
的記憶體區域的存取。在 User mode 中無法存取核心空間。從 User mode 切換至 Kernel mode 必須透過 System call。
- IA-32系統上的定址空間可達 4GB( )。Kernel 分配到 1 GB , User space process 可用空間為 3 GB。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
TODO:
程式碼解讀分工
Youtube
原 Rb 程式碼支援語法
執行流程
執行指令
./rubi progs/fib.rb
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
語言處理器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
lex
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
parser
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
執行程式
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Division
static void mulDivExpr()
為普通的除法,結果會是整數,可透過 .0
or .to_f
將之改為浮點數的結果,但在 rubi 行不通
TODO: 實做正確的整數除法 jserv
fork
參照stdlib.h
裡的structure std_function
operator priority
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
rubi's "expr.dasc"
- 最高優先權:
{
}
[
]
- 第2優先權:
*
/
%
- 第3優先權:
+
-
- 第4優先權:
<
>
!=
==
<=
=>
- 最低優先權:
and
&
or
|
xor

rubi's "stdlib.dasc"

or的規則
上面三行要說明什麼?
課程助教
Concurrent
FORK :fork do
Process.waitall
faster, but expensive, especially if a Copy-on-Write (CoW) is not utilized by the Ruby interpreter
Multiple threads within a single process :
- shared file descriptors
- semaphores (between parent and child forked processes)
- communicate via pipes
- Thanks to the GIL, only one thread can execute at a time.
- Multithreading on RUBY(share address space and memory)
Thread pool with queue(maintain consistency, avoid use of mutex) : Celluloid and its Actor model.deadlock-free
- Background Jobs : without blocking the current thread,examples include Sidekiq, Resque, Delayed Job, and Beanstalkd
@ifStmt()
// didn't simply 'jz =>end' to prevent address diff too large
上面兩行是什麼資訊?
課程助教
Execute
-
<parser.dasc>
-
dasm_init(&d, 1);
只設一個 maxsection,可在這裡修改為多個,以利 concurrency?
-
eval(int pos, int status)
對每一個陳述式 expression 作運算,函數 expression() 對這些第一層結構進行剖析並產生 JIT 機器碼,eval(0, 0) 這個函數幾乎完成了 Rubi JIT compiler 的主要動作。
-
產生的機器碼形式的目的碼,放入 jit_main 這個函數指標中
-
還是不知道 funcTable[] 作用
-
compExpr()
: get argument
Thread

Stack Overflow protection
- Stack canaries
- between buffer & control data
- three types:
- terminator
- random
- random XOR.
- < minilua.c >
checkstack
Function 與 END
parser.h
思考這裡該如何進行 code refactoring,比方說更好的命名,以及 struct 內部成員的調整 jserv
DynASM
這案例不好,我們看不出實際機械碼長什麼樣 jserv
if 實做
指令說明
test
比較兩個數是否相等,實做是將後面接的兩個 operands 做 AND 運算,其運算會更改到 SF, ZF, PF flag。
jnz
全名叫 Jump if not zero,會觀察 ZF,如果 ZF 是0則跳,如果是set
則不跳。
我們做的
由於原本程式在解析的部分參雜了C語言與dasc的code,經由minilua之後產生codegen.c,最後才經過gcc compiler,導致gcc compiler無法偵測parser、expr與stdlib是否有程式碼的語法錯誤或是其他錯誤。
所以我們要做的事情就是把dasc的code部分分開。
原本

後來

Context free Grammar(BNF C版)
Statement
while & for
if & switch
return
end
expression
logical expression
condition expression
add、sub expression
mul、div expression
function
Context free Grammar(BNF Ruby版)
Statement
Primary
THEN & DO
FUNCTION
CALL_ARGS
PRIMARY
問題
- compile 32bit and fails :
features.h:374:25: fatal error: sys/cdefs.h: No such file o+r directory
- <lex.o>was built for i386
參考資料