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 FireStatscialis prices

cialis fast

cialis daily

generic levitra vardenafil

generic cialis from india

cheapest viagra

cost of cialis

buying viagra without prescription

canadian pharmacy viagra legal

canadian generic cialis

online order viagra overnight delivery

buy viagra germany canadian meds

buy cialis without a prescription

cialis canadian cost

online levitra tablet

online cialis

cheapest viagra online

buy cheapest propecia

cialis india

brand cialis

cheap viagra or cialis

how does viagra work

cialis brand name

cialis canada illegal buy

buying cialis

cheap viagra

generic cialis india

canadian healthcare viagra

cialis medication

buying viagra

cialis en mexico

buy levitra us

no prescription viagra

cialis fast delivery

cialis prescription

can i order viagra from the chemist

canadian viagra

canada meds viagra

cialis brand

how to get cialis in canada

index

buy cialis without prescription

cheapest priced propecia

canadian healthcare

buy levitra with no prescription

cialis alternatives

discount cialis levitra viagra

cialis canada online pharmacy

cialis on sale

buy propecia pills

cialis canada

cheap propecia uk

buy propecia canada

canadian pharmacy cialis

cialis from mexico

buy cheapest propecia

levitra 20mg

bestellen levitra

canadian pharmacies cialis

fast propecia

best price for generic cialis

canadian viagra generic

get cialis

discount drug propecia

buy viagra online canada

order usa viagra online

buy pfizer viagra online

buy cialis online uk

buy cialis on line

cialis overnight

cheap canadian viagra

cheap levitra

buy viagra pills

best price cialis

cialis and ketoconazole

buy propecia uk

cialis kanada

cialis kanada

buy propecia international pharmacy

canadian generic viagra online

cialis iop

discount brand name cialis

cialis 20 mg

cialis tablets

cialis by mail

cialis and diarrhea

bying viagra online cheap us

buy cialis online uk

generic viagra 100 mg

cialis canadian

is pfizer viagra available in india

cialis at real low prices

buy viagra mexico

how does viagra work

cialis testimonial

cialis soft canada

canadian pharmacy cialis pfizer

how to get cialis in canada

is pfizer viagra available in india

cialis by women

levitra sales uk

buy cialis

cialis soft

levitra cheap fast

buying cialis in canada

canada propecia prescription

cialis order

levitra online pharmacy

online pharmacy propecia viagra

get levitra online

female viagra

cialis daily cost

cheapest propecia sale uk

best price on propecia

combine cialis and levitra

cialis no prescription

best propecia prices

buy propecia where

cialis next day

levitra now online

best deal for propecia

cialis philippines

cheapest priced propecia

cialis fast delivery

how can i get some cialis

cheap viagra

cialis canada illegal buy

generic cialis canada

canada levitra

lowest cost propecia uk

discount propecia rx

cialis samples

buy propecia no prescription

buying generic propecia

ordering viagra overnight delivery

brand viagra

buy cialis professional

online viagra levitra cialis

cialis for woman

effect of cialis on women

5 mg daily cialis

best levitra prices

canadian generic viagra online

mexico viagra

get viagra fast

generic viagra canadian

how to get viagra

canadian propecia rx

cheapest viagra

generic cialis india discount

buy viagra online cheap us

generic levitra cheap

50 mg cialis dose

best prices for propecia

buy viagra on line

buy cialis online canada

50 mg cialis

cialis buy

buy branded viagra online

buying cialis next day delivery

buy generic viagra india rx

levitra order prescription

buy can from i propecia who

order cheapest propecia online

canadian levitra

buying real viagra without prescription

canada viagra

online propecia uk

buy cialis for daily use

cialis daily dosage pharmacy

generic online propecia

cheapest prices on propecia

buy pfizer viagra in canada

levitra online overnight delivery

overnight delivery cialis

low price propecia

cheap viagra canada or india

best price on propecia

online pharmacy propecia sale

best way to use cialis

cost of viagra

levitra tablet

cialis profesional

best cialis price

online levitra us

best price propecia

buy xenical propecia

levitra vs viagra

buy cheap levitra

cheapest viagra usa

buy propecia international pharmacy

cheap cialis soft

cheap viagra from uk

50 mg cialis

buy propecia without a prescription

cialis cheap us pharmacy

generic levitra overnight delivery

cialis testimonial

brand name cialis overnight

canadian online pharmacy cialis

canadian women viagra

cialis angioplasty

cialis for sale

does generic cialis work

obtain viagra without prescription

cheapest price propecia cheap

lowest price levitra generic online

buy cialis without prescription

buy viagra on line

lowest cost levitra

buying viagra without prescription

levitra best price

cialis angioplasty

buy levitra american pharmacy

levitra low price

cialis dosage

generic propecia online pharmacy

once a day viagra

lowest price for propecia

cialis for woman

cost levitra

buy propecia generic

cialis brand only

brand cialis for sale

best way to take cialis

cheap levitra without prescription

brand name cialis overnight

cialis canadian

cialis en mexico

cialis 5 mg

cheapest propecia in uk

low cost propecia

buy cialis next day delivery

buy propecia in the uk

generic viagra canadian

order levitra

ganeric cialis

canadian pharmacy

canadian viagra and healthcare

canadian healthcare pharmacy

levitra

diuretics and viagra

cialis in canada

buy cheap levitra

online prescription propecia

cialis generic

canada pharmacy propecia

canada online pharmacy levitra

cialis online canada

generic cialis sale