SlideShare a Scribd company logo
Method call in Ruby
Overview
• Ruby ⽤用 rb_control_frame_t 來來儲存 method call 的資訊(但不
是所有 method 都會建⼀一個 frame)
• frame 是存在⼀一個 Stack(Call stack) 裡⾯面,所以⼀一般都叫
Stack frame
• 每個 Stack frame 會有對應的 Instruction 記錄其執⾏行行細節
• 執⾏行行過程中會把 local variable, parameters 存在 Internal stack
• 每個 Stack frame 都會有 PC(Program Counter)管理理
Instruction, SP(Stack Pointer)管理理 Internal stack
範例例程式
Instructions
Instructions
前⾯面定義 method
的 instructions
Instructions
從這開始
Method call in Ruby
PC
Call StackInternal Stack
SP
self
PC
Call StackInternal Stack
SP
foo
PC
Call StackInternal Stack
SP
foo
PC
Call StackInternal Stack
SP
fooself
PC
Call StackInternal Stack
SP
fooself
10
PC
Call StackInternal Stack
SP
foo
double
PC
Call StackInternal Stack
SP
foo
double
PC
10
Call StackInternal Stack
SP
foo
double
10
PC
2
Call StackInternal Stack
SP
foo
double
PC
20
Call StackInternal Stack
SP
foo20
double PC
Call StackInternal Stack
SP
foo
PC
20
Call StackInternal Stack
SP
foo20
PC
Call StackInternal Stack
SP
Call StackInternal Stack
SP
補充
• Ruby ⽤用⼀一個額外的 Stack 來來管理理 method call,但並不
是所有語⾔言都是這樣設計的,其他語⾔言例例如 C++ 或
Java 都是以 Internal stack 中屬於某 method 的⼀一個區
塊作為 Stack frame
• 說明 C++ Call stack 的影片:https://www.youtube.com/
watch?v=1cPSeJLspT8
• UCBerkeley 教授講解 JVM 的執⾏行行細節(50 分鐘但非常
推薦):https://www.youtube.com/watch?
v=HQ3YI70PDe0

More Related Content

Featured (20)

PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
PDF
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
PDF
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
PDF
Everything You Need To Know About ChatGPT
Expeed Software
 
PDF
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
PDF
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
PDF
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
PDF
Skeleton Culture Code
Skeleton Technologies
 
PDF
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
PDF
Content Methodology: A Best Practices Report (Webinar)
contently
 
PPTX
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
PDF
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
PDF
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
PDF
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
PDF
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
PDF
Getting into the tech field. what next
Tessa Mero
 
PDF
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
PDF
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
 
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
 
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 

Method call in Ruby