Archive

Posts Tagged ‘Java’

Register vs. stack based VMs

September 17th, 2009 Derek-Jones 3 comments

Traditionally the virtual machine architecture of choice has been the stack machine; benefits include simplicity of VM implementation, ease of writing a compiler back-end (most VMs are originally designed to host a single language) and code density (i.e., executables for stack architectures are invariably smaller than executables for register architectures).

For a stack architecture to be an effective solution two conditions need to be met:

  • The generated code has to ensure that the top of stack is kept in sync with where the next instruction expects it to be. For instance, on its return a function cannot leave stuff lying around on the stack like it can leave values in registers (whose contents can simply be overwritten).
  • Instruction execution needs to be generally free of state, so an add-two-integers instruction should not have to consult some state variable to find out the size of integers being added. When the value of such state variables have to be saved and restored around function calls they effectively become VM registers.

Cobol is one language where it makes more sense to use a register based VM. I wrote one and designed two machine code generators for the MicroFocus Cobol VM and always find it difficult to explain to people what a very different kind of beast it is compared to the VMs usually encountered.

Parrot, the VM designed as the target for compiled PERL, is register based. A choice driven, I suspect, by the difficulty of ensuring a consistent top-of-stack and perhaps the dynamic typing of the language.

On register based cpus with 64k of storage the code density benefits of a stack based VM are usually sufficient to cancel out the storage overhead of the VM interpreter and support a more feature rich application (provided speed of execution is not crucial).

If storage capacity is not a significant issue and a VM has to be used, what are the runtime performance differences between a register and stack based VM? Answering this question requires compiling and executing the same set of applications for the two kinds of VM. Something that until 2001 nobody had done, or at least not published the results.

A comparison of the Java (stack based) VM with a register VM (The Case for Virtual Register Machines) found that while the stack based code was more compact, fewer instructions needed to be executed on the register based VM.

Most VM instructions are very simple and take relatively little time to execute. When hosted on a pipelined processor the main execution time overhead of a VM is the instruction dispatch (Optimizing Indirect Branch Prediction Accuracy in Virtual Machine Interpreters) and reducing the number of VM instructions executed, even if they are larger and more complicated, can produce a worthwhile performance improvement.

Google has chosen a register based VM for its Android platform. While licensing issues may have been a consideration there are a number of technical advantages to this decision:

  • A register VM is likely to have an intrinsic performance advantage over a stack VM when hosted on a pipelined processor.
  • Byte code verification is likely to be faster on a register VM (i.e., faster startup times) because stack height integrity checks will be greatly simplified.
  • A register VM will be more forgiving of incorrect code (in the VM, generated by the compiler, code corrupted during program transmission or storage attacked by malware) than a stack VM.

Assuming compilers are clever enough (part 1)

May 12th, 2009 Derek-Jones 1 comment

Developers often assume the compiler they use will do all sorts of fancy stuff for them. Is this because they are lazy and happy to push responsibility for parts of the code they write on to the compiler, or do they actually believe that their compiler does all the clever stuff they assume?

An example of unmet assumptions about compiler performance is the use of const in C/C++, final in Java or readonly in other languages. These are often viewed as a checking mechanism, i.e., the developer wants the compiler to check that no attempt is made to, accidentally, change the value of some variable, perhaps via code added during maintenance.

The surprising thing about variables in source code is that approximately 50% of them don’t change once they have been assigned a value (A Theory of Type Qualifiers for C measurements and Automatic Inference of Stationary Fields for Java).

Developers don’t use const/final qualifiers nearly as often as they could. Most modern compilers can deduce if a locally defined variable is only assigned a value once and make use of this fact during optimization. It takes a lot more resources to deduce this information for non-local variables; developers want their compiler to be fast and so implementors don’t won’t them waiting around while whole program analysis is performed.

Why don’t developers make more use of const/final qualifiers? Is this usage, or lack of, an indicator that developers don’t have an accurate grasp of variable usage, or that they don’t see the benefit of using these qualifiers or perhaps they pass responsibility on to the compiler (program size seems to grow sufficiently fast that whole program optimization often consumes more memory than likely to be available; and when are motherboards going to break out of the 4G limit?)

Using local context to disambiguate source

February 12th, 2009 Derek-Jones No comments

Developers can often do a remarkably good job of figuring out what a snippet of code does without seeing (i.e., knowing anything about) most of the declarations of the identifiers involved. In a previous post I discussed how frequency of occurrence information could be used to help parse C without using a symbol table. Other information that could be used is the context in which particular identifiers occur. For instance, in:

f(x);
y = (f)z;

while the code f(x); is probably a function call, the use of f as the type in a cast means that f(x) is actually a definition an object x having type f.

A project investigating the analysis of partial Java programs uses this context information as its sole means of disambiguating Java source (while they do build a symbol table they do not analyze the source of any packages that might be imported). Compared to C Java parsers have it easy, but Java’s richer type system means that semantic analysis can be much more complicated.

On a set of benchmarks the researchers obtained a very reasonable 91.2% accuracy in deducing the type of identifiers.

There are other kinds of information that developers probably use to disambiguate source: the operation that the code is intended to perform and the identifier names. Figuring out the ‘high level’ operation that code performs is a very difficult problem, but the names of Java identifiers have been used to predict object lifetime and appear to be used to help deduce operator precedence. Parsing source by just looking at the identifiers (i.e., treating all punctuators and operators as whitespace) has been on my list of interesting project to do for some time, but projects that are likely to provide a more immediate interesting result keep getting in the way.

FireStats icon Powered by FireStatsbuy cialis online without prescription

cialis by women

buying cialis without a prescription

cialis discount

buying real viagra without prescription

cialis delivered overnight

cialis samples in canada

buy canada levitra

buying levitra online

buy levitra overnight

cialis from mexico

how to buy cialis in canada

levitra mg

buy cialis next day delivery

buy viagra in canada

lowest propecia 1 mg

cialis daily

canadian viagra and healthcare

levitra in mexico

levitra sale

levitra online us

online cheap viagra

generic viagra canadian

buy propecia online usa

5 mg original brand cialis

buy propecia online pharmacy

natural levitra

how does viagra work

canada viagra

low price levitra

buy real viagra online

cialis from canada

cheap viagra or cialis

cheapest prices for viagra

cialis in mexico

buying viagra in canada

cialis in canada

cheapest propecia uk

buying viagra with no prescription

cheapest overnight cialis

cialis express delivery

cialis dose

cialis generic 100 mg

cialis generic

best way to take cialis

cheap viagra no prescription

online pharmacy propecia renova

buy cheap online propecia

cialis no prescription

cialis iop

name brand cialis

cialis alternative

levitra order prescription

best levitra prices

cialis overnight delivery

canadian viagra generic

buying propecia

buy viagra online cheap us

5 mg cialis

cialis cost canada

buy cheap generic propecia

buying viagra

discount levitra online us

buy pfizer viagra

dosage levitra

levitra prescription

cialis by women

buying cialis soft tabs 100 mg

cialis blood thinner

generic viagra online

best levitra price

best price generic propecia

cheap viagra from uk

cialis india pharmacy

generic cialis next day delivery

cheap viagra or cialis

cialis uk

order propecia now

best propecia prices

buying online propecia

canadian levitra

cheapest prices on viagra

canadian cialis

buy mg propecia

no prescription propecia

buying viagra

overnight delivery cialis

buy cialis in usa

buy cialis without a prescription

cialis usa

cialis 50 mg

cialis pharmacy

buying cialis online

buy propecia without prescription

buy cheap online propecia

bio viagra herbal

buy propecia online without prescription

cialis profesional

how much does cialis cost

cheapest propecia in uk

how to get viagra

discount viagra

order levitra online

fda levitra

cialis daily dosage pharmacy

get cialis online

buy viagra on line

baldness male propecia

buy generic levitra

buy propecia generic

buy mg propecia

buy cheapest cialis

buy cheap propecia

cialis strenght mg

buy xenical propecia

buy cialis in canada

cialis india

cialis order

order cheapest propecia online

beta blockers and viagra

generic levitra cheap

cheapest prices on propecia

levitra in india

buy cialis once daily

cheap online levitra

info levitra

cialis headaches

cialis one a day

cialis philippines

buying viagra in canada

cialis daily canada

cialis tablets foreign

baldness male propecia

index

buy cheap generic levitra

index

best price for generic cialis

canadian drugs propecia

buying generic cialis mexico rx

cialis canada

ordering cialis gel

buy pfizer viagra in canada

cialis and canada custom

best cialis price

best way to take cialis

cheap viagra pills

buying viagra in the us

cialis professional

buy cheap levitra

buy real cialis

generic viagra 100 mg

brand cialis for sale

canadian healthcare

levitra tabs

cialis on sale

buy viagra china

best way to use cialis

ordering viagra

buying real viagra without prescription

buy propecia pills

canada online pharmacy propecia

buy propecia cheap

buy viagra pills

cialis fast delivery usa

generic cialis soft tabs

order cheap levitra

buy canada in propecia

cialis for less 20 mg

get cialis online

ordering viagra overnight delivery

ordering propecia

cialis from mexico

generic viagra

generic propecia for sale

levitra cheap canadian pharmacy

cheapest viagra

cost of cialis

generic propecia effective

generic propecia online pharmacy

buy real viagra online

low cost canadian viagra

cialis canadian cost

buy branded viagra online

canadian women viagra

cialis and diarrhea

cheap canadian viagra

buy cialis on line

discount real viagra

cialis vs levitra

cheap propecia online prescription

cialis germany

cost of propecia

buy pfizer viagra

cheapest propecia uk

liquid propecia

no prescription viagra

cialis price 100 mg

canadian viagra and healthcare

online generic cialis 100 mg

best viagra

cheap levitra online

best levitra price

online propecia prescriptions

cialis once daily

buy viagra without prescription

how much is viagra

effect of cialis on women

cheap generic levitra

best way to use cialis

china viagra

levitra best price

best online generic levitra

cialis soft

cialis kanada

buy cialis online uk

cheap order prescription propecia

low cost viagra

canada generic propecia

online pharmacy levitra

online order propecia

cheap online propecia

cialis soft pills

buy viagra mexico

buy propecia without prescription

buy branded viagra

brand viagra

cost of cialis

buy cialis online uk

cialis price in canada

cialis pfizer

best price for propecia

daily cialis cost

canadian pharmacy

buy propecia online prescription

buying cialis

buying viagra without prescription

buy cialis online

cialis professional 20 mg

drug hair loss propecia

buy propecia online cheap pharmacy

cialis from india

online pharmacy cost levitra

levitra vs cialis

cialis blood thinner

discount cialis levitra viagra

buy cialis for daily use

cheapest priced propecia

canadian propecia rx

buy discount viagra

cialis 5 mg