1*9880d681SAndroid Build Coastguard WorkerDate: Sun, 19 Nov 2000 16:23:57 -0600 (CST) 2*9880d681SAndroid Build Coastguard WorkerFrom: Chris Lattner <[email protected]> 3*9880d681SAndroid Build Coastguard WorkerTo: Vikram Adve <[email protected]> 4*9880d681SAndroid Build Coastguard WorkerSubject: Re: a few thoughts 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard WorkerOkay... here are a few of my thoughts on this (it's good to know that we 7*9880d681SAndroid Build Coastguard Workerthink so alike!): 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Worker> 1. We need to be clear on our goals for the VM. Do we want to emphasize 10*9880d681SAndroid Build Coastguard Worker> portability and safety like the Java VM? Or shall we focus on the 11*9880d681SAndroid Build Coastguard Worker> architecture interface first (i.e., consider the code generation and 12*9880d681SAndroid Build Coastguard Worker> processor issues), since the architecture interface question is also 13*9880d681SAndroid Build Coastguard Worker> important for portable Java-type VMs? 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard WorkerI forsee the architecture looking kinda like this: (which is completely 16*9880d681SAndroid Build Coastguard Workersubject to change) 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker1. The VM code is NOT guaranteed safe in a java sense. Doing so makes it 19*9880d681SAndroid Build Coastguard Worker basically impossible to support C like languages. Besides that, 20*9880d681SAndroid Build Coastguard Worker certifying a register based language as safe at run time would be a 21*9880d681SAndroid Build Coastguard Worker pretty expensive operation to have to do. Additionally, we would like 22*9880d681SAndroid Build Coastguard Worker to be able to statically eliminate many bounds checks in Java 23*9880d681SAndroid Build Coastguard Worker programs... for example. 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker 2. Instead, we can do the following (eventually): 26*9880d681SAndroid Build Coastguard Worker * Java bytecode is used as our "safe" representation (to avoid 27*9880d681SAndroid Build Coastguard Worker reinventing something that we don't add much value to). When the 28*9880d681SAndroid Build Coastguard Worker user chooses to execute Java bytecodes directly (ie, not 29*9880d681SAndroid Build Coastguard Worker precompiled) the runtime compiler can do some very simple 30*9880d681SAndroid Build Coastguard Worker transformations (JIT style) to convert it into valid input for our 31*9880d681SAndroid Build Coastguard Worker VM. Performance is not wonderful, but it works right. 32*9880d681SAndroid Build Coastguard Worker * The file is scheduled to be compiled (rigorously) at a later 33*9880d681SAndroid Build Coastguard Worker time. This could be done by some background process or by a second 34*9880d681SAndroid Build Coastguard Worker processor in the system during idle time or something... 35*9880d681SAndroid Build Coastguard Worker * To keep things "safe" ie to enforce a sandbox on Java/foreign code, 36*9880d681SAndroid Build Coastguard Worker we could sign the generated VM code with a host specific private 37*9880d681SAndroid Build Coastguard Worker key. Then before the code is executed/loaded, we can check to see if 38*9880d681SAndroid Build Coastguard Worker the trusted compiler generated the code. This would be much quicker 39*9880d681SAndroid Build Coastguard Worker than having to validate consistency (especially if bounds checks have 40*9880d681SAndroid Build Coastguard Worker been removed, for example) 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker> This is important because the audiences for these two goals are very 43*9880d681SAndroid Build Coastguard Worker> different. Architects and many compiler people care much more about 44*9880d681SAndroid Build Coastguard Worker> the second question. The Java compiler and OS community care much more 45*9880d681SAndroid Build Coastguard Worker> about the first one. 46*9880d681SAndroid Build Coastguard Worker 47*9880d681SAndroid Build Coastguard Worker3. By focusing on a more low level virtual machine, we have much more room 48*9880d681SAndroid Build Coastguard Worker for value add. The nice safe "sandbox" VM can be provided as a layer 49*9880d681SAndroid Build Coastguard Worker on top of it. It also lets us focus on the more interesting compilers 50*9880d681SAndroid Build Coastguard Worker related projects. 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker> 2. Design issues to consider (an initial list that we should continue 53*9880d681SAndroid Build Coastguard Worker> to modify). Note that I'm not trying to suggest actual solutions here, 54*9880d681SAndroid Build Coastguard Worker> but just various directions we can pursue: 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard WorkerUnderstood. :) 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker> a. A single-assignment VM, which we've both already been thinking 59*9880d681SAndroid Build Coastguard Worker> about. 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard WorkerYup, I think that this makes a lot of sense. I am still intrigued, 62*9880d681SAndroid Build Coastguard Workerhowever, by the prospect of a minimally allocated VM representation... I 63*9880d681SAndroid Build Coastguard Workerthink that it could have definite advantages for certain applications 64*9880d681SAndroid Build Coastguard Worker(think very small machines, like PDAs). I don't, however, think that our 65*9880d681SAndroid Build Coastguard Workerinitial implementations should focus on this. :) 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard WorkerHere are some other auxiliary goals that I think we should consider: 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker1. Primary goal: Support a high performance dynamic compilation 70*9880d681SAndroid Build Coastguard Worker system. This means that we have an "ideal" division of labor between 71*9880d681SAndroid Build Coastguard Worker the runtime and static compilers. Of course, the other goals of the 72*9880d681SAndroid Build Coastguard Worker system somewhat reduce the importance of this point (f.e. portability 73*9880d681SAndroid Build Coastguard Worker reduces performance, but hopefully not much) 74*9880d681SAndroid Build Coastguard Worker2. Portability to different processors. Since we are most familiar with 75*9880d681SAndroid Build Coastguard Worker x86 and solaris, I think that these two are excellent candidates when 76*9880d681SAndroid Build Coastguard Worker we get that far... 77*9880d681SAndroid Build Coastguard Worker3. Support for all languages & styles of programming (general purpose 78*9880d681SAndroid Build Coastguard Worker VM). This is the point that disallows java style bytecodes, where all 79*9880d681SAndroid Build Coastguard Worker array refs are checked for bounds, etc... 80*9880d681SAndroid Build Coastguard Worker4. Support linking between different language families. For example, call 81*9880d681SAndroid Build Coastguard Worker C functions directly from Java without using the nasty/slow/gross JNI 82*9880d681SAndroid Build Coastguard Worker layer. This involves several subpoints: 83*9880d681SAndroid Build Coastguard Worker A. Support for languages that require garbage collectors and integration 84*9880d681SAndroid Build Coastguard Worker with languages that don't. As a base point, we could insist on 85*9880d681SAndroid Build Coastguard Worker always using a conservative GC, but implement free as a noop, f.e. 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Worker> b. A strongly-typed VM. One question is do we need the types to be 88*9880d681SAndroid Build Coastguard Worker> explicitly declared or should they be inferred by the dynamic 89*9880d681SAndroid Build Coastguard Worker> compiler? 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker B. This is kind of similar to another idea that I have: make OOP 92*9880d681SAndroid Build Coastguard Worker constructs (virtual function tables, class heirarchies, etc) explicit 93*9880d681SAndroid Build Coastguard Worker in the VM representation. I believe that the number of additional 94*9880d681SAndroid Build Coastguard Worker constructs would be fairly low, but would give us lots of important 95*9880d681SAndroid Build Coastguard Worker information... something else that would/could be important is to 96*9880d681SAndroid Build Coastguard Worker have exceptions as first class types so that they would be handled in 97*9880d681SAndroid Build Coastguard Worker a uniform way for the entire VM... so that C functions can call Java 98*9880d681SAndroid Build Coastguard Worker functions for example... 99*9880d681SAndroid Build Coastguard Worker 100*9880d681SAndroid Build Coastguard Worker> c. How do we get more high-level information into the VM while keeping 101*9880d681SAndroid Build Coastguard Worker> to a low-level VM design? 102*9880d681SAndroid Build Coastguard Worker> o Explicit array references as operands? An alternative is 103*9880d681SAndroid Build Coastguard Worker> to have just an array type, and let the index computations be 104*9880d681SAndroid Build Coastguard Worker> separate 3-operand instructions. 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker C. In the model I was thinking of (subject to change of course), we 107*9880d681SAndroid Build Coastguard Worker would just have an array type (distinct from the pointer 108*9880d681SAndroid Build Coastguard Worker types). This would allow us to have arbitrarily complex index 109*9880d681SAndroid Build Coastguard Worker expressions, while still distinguishing "load" from "Array load", 110*9880d681SAndroid Build Coastguard Worker for example. Perhaps also, switch jump tables would be first class 111*9880d681SAndroid Build Coastguard Worker types as well? This would allow better reasoning about the program. 112*9880d681SAndroid Build Coastguard Worker 113*9880d681SAndroid Build Coastguard Worker5. Support dynamic loading of code from various sources. Already 114*9880d681SAndroid Build Coastguard Worker mentioned above was the example of loading java bytecodes, but we want 115*9880d681SAndroid Build Coastguard Worker to support dynamic loading of VM code as well. This makes the job of 116*9880d681SAndroid Build Coastguard Worker the runtime compiler much more interesting: it can do interprocedural 117*9880d681SAndroid Build Coastguard Worker optimizations that the static compiler can't do, because it doesn't 118*9880d681SAndroid Build Coastguard Worker have all of the required information (for example, inlining from 119*9880d681SAndroid Build Coastguard Worker shared libraries, etc...) 120*9880d681SAndroid Build Coastguard Worker 121*9880d681SAndroid Build Coastguard Worker6. Define a set of generally useful annotations to add to the VM 122*9880d681SAndroid Build Coastguard Worker representation. For example, a function can be analysed to see if it 123*9880d681SAndroid Build Coastguard Worker has any sideeffects when run... also, the MOD/REF sets could be 124*9880d681SAndroid Build Coastguard Worker calculated, etc... we would have to determine what is reasonable. This 125*9880d681SAndroid Build Coastguard Worker would generally be used to make IP optimizations cheaper for the 126*9880d681SAndroid Build Coastguard Worker runtime compiler... 127*9880d681SAndroid Build Coastguard Worker 128*9880d681SAndroid Build Coastguard Worker> o Explicit instructions to handle aliasing, e.g.s: 129*9880d681SAndroid Build Coastguard Worker> -- an instruction to say "I speculate that these two values are not 130*9880d681SAndroid Build Coastguard Worker> aliased, but check at runtime", like speculative execution in 131*9880d681SAndroid Build Coastguard Worker> EPIC? 132*9880d681SAndroid Build Coastguard Worker> -- or an instruction to check whether two values are aliased and 133*9880d681SAndroid Build Coastguard Worker> execute different code depending on the answer, somewhat like 134*9880d681SAndroid Build Coastguard Worker> predicated code in EPIC 135*9880d681SAndroid Build Coastguard Worker 136*9880d681SAndroid Build Coastguard WorkerThese are also very good points... if this can be determined at compile 137*9880d681SAndroid Build Coastguard Workertime. I think that an epic style of representation (not the instruction 138*9880d681SAndroid Build Coastguard Workerpacking, just the information presented) could be a very interesting model 139*9880d681SAndroid Build Coastguard Workerto use... more later... 140*9880d681SAndroid Build Coastguard Worker 141*9880d681SAndroid Build Coastguard Worker> o (This one is a difficult but powerful idea.) 142*9880d681SAndroid Build Coastguard Worker> A "thread-id" field on every instruction that allows the static 143*9880d681SAndroid Build Coastguard Worker> compiler to generate a set of parallel threads, and then have 144*9880d681SAndroid Build Coastguard Worker> the runtime compiler and hardware do what they please with it. 145*9880d681SAndroid Build Coastguard Worker> This has very powerful uses, but thread-id on every instruction 146*9880d681SAndroid Build Coastguard Worker> is expensive in terms of instruction size and code size. 147*9880d681SAndroid Build Coastguard Worker> We would need to compactly encode it somehow. 148*9880d681SAndroid Build Coastguard Worker 149*9880d681SAndroid Build Coastguard WorkerYes yes yes! :) I think it would be *VERY* useful to include this kind 150*9880d681SAndroid Build Coastguard Workerof information (which EPIC architectures *implicitly* encode. The trend 151*9880d681SAndroid Build Coastguard Workerthat we are seeing supports this greatly: 152*9880d681SAndroid Build Coastguard Worker 153*9880d681SAndroid Build Coastguard Worker1. Commodity processors are getting massive SIMD support: 154*9880d681SAndroid Build Coastguard Worker * Intel/Amd MMX/MMX2 155*9880d681SAndroid Build Coastguard Worker * AMD's 3Dnow! 156*9880d681SAndroid Build Coastguard Worker * Intel's SSE/SSE2 157*9880d681SAndroid Build Coastguard Worker * Sun's VIS 158*9880d681SAndroid Build Coastguard Worker2. SMP is becoming much more common, especially in the server space. 159*9880d681SAndroid Build Coastguard Worker3. Multiple processors on a die are right around the corner. 160*9880d681SAndroid Build Coastguard Worker 161*9880d681SAndroid Build Coastguard WorkerIf nothing else, not designing this in would severely limit our future 162*9880d681SAndroid Build Coastguard Workerexpansion of the project... 163*9880d681SAndroid Build Coastguard Worker 164*9880d681SAndroid Build Coastguard Worker> Also, this will require some reading on at least two other 165*9880d681SAndroid Build Coastguard Worker> projects: 166*9880d681SAndroid Build Coastguard Worker> -- Multiscalar architecture from Wisconsin 167*9880d681SAndroid Build Coastguard Worker> -- Simultaneous multithreading architecture from Washington 168*9880d681SAndroid Build Coastguard Worker> 169*9880d681SAndroid Build Coastguard Worker> o Or forget all this and stick to a traditional instruction set? 170*9880d681SAndroid Build Coastguard Worker 171*9880d681SAndroid Build Coastguard WorkerHeh... :) Well, from a pure research point of view, it is almost more 172*9880d681SAndroid Build Coastguard Workerattactive to go with the most extreme/different ISA possible. On one axis 173*9880d681SAndroid Build Coastguard Workeryou get safety and conservatism, and on the other you get degree of 174*9880d681SAndroid Build Coastguard Workerinfluence that the results have. Of course the problem with pure research 175*9880d681SAndroid Build Coastguard Workeris that often times there is no concrete product of the research... :) 176*9880d681SAndroid Build Coastguard Worker 177*9880d681SAndroid Build Coastguard Worker> BTW, on an unrelated note, after the meeting yesterday, I did remember 178*9880d681SAndroid Build Coastguard Worker> that you had suggested doing instruction scheduling on SSA form instead 179*9880d681SAndroid Build Coastguard Worker> of a dependence DAG earlier in the semester. When we talked about 180*9880d681SAndroid Build Coastguard Worker> it yesterday, I didn't remember where the idea had come from but I 181*9880d681SAndroid Build Coastguard Worker> remembered later. Just giving credit where its due... 182*9880d681SAndroid Build Coastguard Worker 183*9880d681SAndroid Build Coastguard Worker:) Thanks. 184*9880d681SAndroid Build Coastguard Worker 185*9880d681SAndroid Build Coastguard Worker> Perhaps you can save the above as a file under RCS so you and I can 186*9880d681SAndroid Build Coastguard Worker> continue to expand on this. 187*9880d681SAndroid Build Coastguard Worker 188*9880d681SAndroid Build Coastguard WorkerI think it makes sense to do so when we get our ideas more formalized and 189*9880d681SAndroid Build Coastguard Workerbounce it back and forth a couple of times... then I'll do a more formal 190*9880d681SAndroid Build Coastguard Workerwriteup of our goals and ideas. Obviously our first implementation will 191*9880d681SAndroid Build Coastguard Workernot want to do all of the stuff that I pointed out above... be we will 192*9880d681SAndroid Build Coastguard Workerwant to design the project so that we do not artificially limit ourselves 193*9880d681SAndroid Build Coastguard Workerat sometime in the future... 194*9880d681SAndroid Build Coastguard Worker 195*9880d681SAndroid Build Coastguard WorkerAnyways, let me know what you think about these ideas... and if they sound 196*9880d681SAndroid Build Coastguard Workerreasonable... 197*9880d681SAndroid Build Coastguard Worker 198*9880d681SAndroid Build Coastguard Worker-Chris 199*9880d681SAndroid Build Coastguard Worker 200