Introduction
The PHP Opcode series will take a look at the theory and implementation of working with the Zend Engine in the specific areas of adding opcodes and enabling language features. The specific areas will be how it would look in the PHP language, how it would look as PHP opcodes, and how it would look as Assembler for looking at enabling JIT compiling later.
The posts will be researched and go through multiple drafts for professionalism before posting. In this hope, it will strive to enable discussion that isn’t flaming and collective of the topic at hand. For as much as I can achieve at my level of writing skill and researching the topic at hand.
(Honestly, I’m spending more time on these posts than I do on my school research papers… which is to still say that I am doing more than previous posts.)
Purpose
I want to add JIT compiling to the current Zend Engine and before I can do that I will have to learn how the Zend Engine works. The best way would be to read a book or learn from the minds that created it. There is a current lack of printed material on extending the Zend Engine and I’ll rather not bother the Zend Engine masters with my countless n00bish questions. I’ll wait to ask those questions for whenever I hit a road block or can’t find the answer myself.
I’m going to try to implement some of the easier features of the “Opcode Theory” part to learn how different areas of the Zend Engine work. I’ll also intentionally break the Engine and learn from there. Such questions as, “I wonder what would happen if I add this?” or “What if I change this to my own code.”
I’m tempted to rewrite the entire thing to my achieve my own goals, but that would negate the point of these exercises.
Not that I will implement all of the theory, but to think about how it would be possible. To learn how PHP uses Opcodes and how it can be improved and optimized by using more. By writing theory and how the current Zend Engine works, I can remember better and try to implement my ideas to see if they are possible.
Areas of Focus
There will be areas of focus with titles for keeping order of which post is for what.
- Opcode Theory
- Opcode Implementation
- Opcode Documentation
Opcode Theory
These posts will abstract out the problem and how it could look once implemented. From above, the sections will be PHP userland code, PHP Opcode, and finally how it would look as Assembler for JIT. The Assembler isn’t much use for the JIT, but it will help to think about solutions once JIT is finally implemented. The JIT and Assembler will achieve the same functionality of converting opcodes to machine code.
It would be nice to see it in action outside of PHP, using Assembler, before implementing the feature using the JIT library. Getting Assembler code to work against the Zend Engine and PHP will also be part of the Implementation, which is outside the scope of the Theory. It is just to say that the Theory part will have puesdo-Assembler code for how it might look.
I will not be implementing all of these theory posts and I will be lucky if I even implement one. My main purpose is learning enough of the Opcode parts of the Zend Engine to hook into and write a Zend Engine extension that enables JIT compilation. These side projects should help to learn enough to accomplish that much.
Opcode Implementation
Will document how well I’m doing implementing some of the theory and eventually the JIT feature for the Zend Engine. In the event that I do implement one of the features in the theory part, I will post what it finally looks like and how it works. These posts will also include the road and difficulties in implementing the features in the theory posts and eventually how it was done.
Opcode Documentation
I expect that I’ll learn a lot by the above mangling of the Zend Engine and picking at the minds and team behind the Zend Engine. Some things I will have to learn myself and I’ll post them in this heading to make sure that I’ll remember them when I come back after an extended break or two to work on other projects.
“Hmm, how did I do that one thing again? Oh yeah, I wrote about that!” and also to store help I will eventually (hopefully) receive from the PHP lists.
Possibly Related Posts: