SlideShare a Scribd company logo
Explaining exception handling on Zend VM






❖
❖
❖
❖
❖
Zend VMにおける例外の実装
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
<?php
function mydiv($a, $b) {
return $b ? $a / $b : 0;
}
$ php -dopcache.enable_cli=1 -dopcache.opt_debug_level=0x10000 mydiv.php
L0 (2): CV0($a) = RECV 1
L1 (2): CV1($b) = RECV 2
L2 (3): JMPZ CV1($b) L6
L3 (3): T2 = DIV CV0($a) CV1($b)
L4 (3): T3 = QM_ASSIGN T2
L5 (3): JMP L7
L6 (3): T3 = QM_ASSIGN int(0)
L7 (3): RETURN T3
L8 (4): RETURN null
❖
❖
❖
❖
JMPZ CV1($b) L6
T2 = DIV CV0($a) CV1($b)
❖
Zend VMにおける例外の実装
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
<?php
function bar() {
$e = new Exception();
throw $e;
try {
throw $e;
} catch (FooException $e) {
throw $e;
} catch (BarException $e) {
return 0;
}
}
❖
L0 (4): V1 = NEW 0 string("Exception")
L1 (4): DO_FCALL
L2 (3): ASSIGN CV0($e) V1
L3 (4): THROW CV0($e)
L4 (6): THROW CV0($e)
L5 (6): JMP L11
L6 (7): CV0($e) = CATCH string("FooException") L9
L7 (8): THROW CV0($e)
L8 (8): JMP L11
L9 (9): CV0($e) = CATCH string("BarException")
L10 (10): RETURN int(0)
L11 (12): RETURN null
EXCEPTION TABLE:
L4, L6, -, -
❖
Zend VMにおける例外の実装
❖
THROW CV0($e)
❖
CV0($e) = CATCH string("FooException") L9
Zend VMにおける例外の実装
Zend VMにおける例外の実装
❖
❖
❖
❖
THROW CV0($e)
ZEND_API ZEND_COLD void zend_throw_exception_internal 
(zval *exception) /* {{{ */
{
if (exception != NULL) {
EG(exception) = Z_OBJ_P(exception);
❖
❖
❖
EG(current_execute_data)->opline = EG(exception_op);
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖ 

L0 (4): V1 = NEW 0 string("Exception")
L1 (4): DO_FCALL
L2 (3): ASSIGN CV0($e) V1
L3 (4): THROW CV0($e)
L4 (6): THROW CV0($e)
L5 (6): JMP L11
L6 (7): CV0($e) = CATCH string("FooException") L9
L7 (8): THROW CV0($e)
L8 (8): JMP L11
L9 (9): CV0($e) = CATCH string("BarException")
L10 (10): RETURN int(0)
L11 (12): RETURN null
EXCEPTION TABLE:
L4, L6, -, -
❖
❖
❖
❖
❖
if (ce != catch_ce) {
if (!catch_ce || !instanceof_function(ce, catch_ce)) {
if (opline->extended_value & ZEND_LAST_CATCH) {
zend_rethrow_exception(execute_data);
HANDLE_EXCEPTION();
}
ZEND_VM_JMP_EX(OP_JMP_ADDR(opline, opline->op2), 0);
}
}
❖
❖
❖
❖
static zend_always_inline void 
zend_rethrow_exception(zend_execute_data *execute_data)
{
if (EX(opline)->opcode != ZEND_HANDLE_EXCEPTION) {
EG(opline_before_exception) = EX(opline);
EX(opline) = EG(exception_op);
}
}
❖
❖
❖
❖
❖
THROW CV0($e)
❖
HANDLE_EXEPTION
CV0($e) = CATCH string("FooException") L9
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖ 

❖
❖
❖
❖
<?php
function baz() {
try {
throw new Exception();
} finally {
return 0;
}
}
❖
<?php
function baz() {
try {
throw new Exception();
} finally {
return 0;
}
}
❖
❖
❖
L0 (4): V1 = NEW 0 string("Exception")
L1 (4): DO_FCALL
L2 (4): THROW V1
L3 (5): T0 = FAST_CALL L5
L4 (5): JMP L8
L5 (6): DISCARD_EXCEPTION T0
L6 (6): RETURN int(0)
L7 (6): FAST_RET T0
L8 (8): RETURN null
EXCEPTION TABLE:
L0, -, L5, L7
❖
❖ 

❖
❖
❖
❖
<?php
function baz() {
try {
throw new Exception(1);
} finally {
throw new Exception(2);
}
}
❖
<?php
function baz() {
try {
throw new Exception(1);
} finally {
throw new Exception(2);
}
}
❖
❖
try {
baz();
} catch (Exception $e) {
echo $e->getMessage(); // 2
echo $e->getPrevious()->getMessage(); // 1
}
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
❖
Zend VMにおける例外の実装

More Related Content

PDF
Zend VMにおける例外の実装
PDF
Multiplication/Division Reference Sheet Answers
DOCX
StewartPlatform_cpp
DOCX
Primer Punto
KEY
「Frama-Cによるソースコード検証」 (mzp)
PDF
Perl6 operators and metaoperators
PDF
Laravel - PHP For artisans
DOC
basic shell_programs
Zend VMにおける例外の実装
Multiplication/Division Reference Sheet Answers
StewartPlatform_cpp
Primer Punto
「Frama-Cによるソースコード検証」 (mzp)
Perl6 operators and metaoperators
Laravel - PHP For artisans
basic shell_programs

What's hot (20)

PDF
The Ring programming language version 1.6 book - Part 84 of 189
PPTX
PHP in 2018 - Q4 - AFUP Limoges
PDF
GeoGebra JavaScript CheatSheet
PDF
MATHS SYMBOLS - #2 - EXPONENTIALS and LOGARITHMS
DOC
Advanced pointer
PDF
Scala Under the Hood / ScalaSwarm
PDF
Functional Programming: An Introduction
DOCX
DOC
Final ds record
PDF
The Ring programming language version 1.4.1 book - Part 22 of 31
PPTX
ภาษาซี
DOC
Tarea De Scilab By Sebastian Vasquez
PPTX
Integração com cics
PDF
smtlecture.9
PPTX
ภาษาซี
PDF
CROCHET - Checkpoint Rollback in JVM (ECOOP 2018)
PDF
Exakat for PHP : smart code reviewing engine
DOCX
Quinto Punto Parte B
The Ring programming language version 1.6 book - Part 84 of 189
PHP in 2018 - Q4 - AFUP Limoges
GeoGebra JavaScript CheatSheet
MATHS SYMBOLS - #2 - EXPONENTIALS and LOGARITHMS
Advanced pointer
Scala Under the Hood / ScalaSwarm
Functional Programming: An Introduction
Final ds record
The Ring programming language version 1.4.1 book - Part 22 of 31
ภาษาซี
Tarea De Scilab By Sebastian Vasquez
Integração com cics
smtlecture.9
ภาษาซี
CROCHET - Checkpoint Rollback in JVM (ECOOP 2018)
Exakat for PHP : smart code reviewing engine
Quinto Punto Parte B
Ad

Similar to Zend VMにおける例外の実装 (6)

PDF
PHP Internals and Virtual Machine
PPT
PHP Exception handler
PDF
Php exceptions
PDF
Php engine
PPTX
Php Extensions for Dummies
PDF
Zend Framework 2 Patterns
PHP Internals and Virtual Machine
PHP Exception handler
Php exceptions
Php engine
Php Extensions for Dummies
Zend Framework 2 Patterns
Ad

More from Yoshio Hanawa (20)

PPTX
自宅の消費電力をリアルタイムに グラフ化してみた
PDF
ぼくのかんがえる
さいきょうの銀行振込
PDF
「OKグーグル! 銀行振込1000円」
PDF
浮動小数点数とOSSのバグの話
PDF
PHP拡張をPECLに登録してわかったこと
PDF
GitHubからお金をもらった話
PDF
iOS/macOSとAndroid/Linuxのサンドボックス機構について調べた
PDF
realpathキャッシュと OPcacheの面倒すぎる関係
PDF
家庭用ブロードバンドルータ上でWordPressを動かそう
PDF
Laungage Update PHP編
PDF
PHPの拡張モジュールをGoで作る
PDF
GitHubにバグ報告して賞金$500を頂いた話
PDF
php-buildがいかに便利かを力説する
PDF
OPcacheの新機能ファイルベースキャッシュの内部実装を読んでみた
PDF
PHP7の拡張モジュール事情
PDF
PHP7の内部実装から学ぶ性能改善テクニック
PDF
PHPの正規表現と最長一致
PDF
PHP7で変わること ——言語仕様とエンジンの改善ポイント
PDF
偶然にも500万個のSSH公開鍵を手に入れた俺たちは
PDF
PHP7はなぜ速いのか
自宅の消費電力をリアルタイムに グラフ化してみた
ぼくのかんがえる
さいきょうの銀行振込
「OKグーグル! 銀行振込1000円」
浮動小数点数とOSSのバグの話
PHP拡張をPECLに登録してわかったこと
GitHubからお金をもらった話
iOS/macOSとAndroid/Linuxのサンドボックス機構について調べた
realpathキャッシュと OPcacheの面倒すぎる関係
家庭用ブロードバンドルータ上でWordPressを動かそう
Laungage Update PHP編
PHPの拡張モジュールをGoで作る
GitHubにバグ報告して賞金$500を頂いた話
php-buildがいかに便利かを力説する
OPcacheの新機能ファイルベースキャッシュの内部実装を読んでみた
PHP7の拡張モジュール事情
PHP7の内部実装から学ぶ性能改善テクニック
PHPの正規表現と最長一致
PHP7で変わること ——言語仕様とエンジンの改善ポイント
偶然にも500万個のSSH公開鍵を手に入れた俺たちは
PHP7はなぜ速いのか

Recently uploaded (20)

PPTX
Transform Your Business with a Software ERP System
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Understanding Forklifts - TECH EHS Solution
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Transform Your Business with a Software ERP System
VVF-Customer-Presentation2025-Ver1.9.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Understanding Forklifts - TECH EHS Solution
PTS Company Brochure 2025 (1).pdf.......
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Odoo POS Development Services by CandidRoot Solutions
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Online Work Permit System for Fast Permit Processing
ISO 45001 Occupational Health and Safety Management System
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Which alternative to Crystal Reports is best for small or large businesses.pdf
Operating system designcfffgfgggggggvggggggggg
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

Zend VMにおける例外の実装