Welcome to Emulationworld

Forum Index | FAQ | New User | Login | Search

Make a New PostPrevious ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectDynarec using java and BCEL Reply to this message
Posted byerikduijs
Posted on07/29/04 05:18 PM



We're looking into applying dynamic recompilation using the BCEL library in java for JEmu2. I think we came up with a rather solid way to do it (probably the way everybody does it).
For the CPU emu's JEmu2 currently supports, the speed gain will probably not be too important (the main bottleneck is rendering right now by far, which I'm dealing with as well), but I plan on adding 68k emulation as well and there it might become more important.

What are typically the speed gains that are possible with dynarec?
I'm thinking about doing dead flag removal as well, but I have the feeling it might not make much of a difference when doing it in java since these kinds of things are typically those things that HotSpot should be very good at.
Does anybody have experience with this, and especially using java? Is there some good documentation somewhere about dynarec techniques that I should be aware about? Thoughts, suggestions?




SubjectRe: Dynarec using java and BCEL new Reply to this message
Posted byBart T.
Posted on07/30/04 08:33 PM



> What are typically the speed gains that are possible with dynarec?

It depends on the system, the processor being emulated, and the nature of the code. The speed gains can be very high in the right situations.

> I'm thinking about doing dead flag removal as well, but I have the feeling it
> might not make much of a difference when doing it in java since these kinds of
> things are typically those things that HotSpot should be very good at.

Dead flag removal is definitely an optimization that's worthwhile for many older CISC processors with lots of flags (especially 68K.)


> Does anybody have experience with this, and especially using java? Is there some
> good documentation somewhere about dynarec techniques that I should be aware
> about? Thoughts, suggestions?

I don't know anything about using Java but you might want to turn to the dynarec mailing list if you want to discuss the subject.



----
Bart


SubjectRe: Dynarec using java and BCEL new Reply to this message
Posted byRiff
Posted on08/02/04 03:27 PM



> What are typically the speed gains that are possible with dynarec?

If you read the literature, the highest gains tend to be around 20% to 30% when performing dynamic optimization on native code. Performance gains become more uncertain when the input is non-native binary code. In this case, its going to be highly dependent on the difference between the destination architecture and the source architecture. If the destination processor cannot natively execute code written for the source processor, and you do not translate to native code, you have no choice but to use an interpreter loop. Even when emulating complex architectures, an interpreter will often spend a good 5 to 10% of its time just performing indirect calls to instruction handlers and performing book keeping. If you execute optimized IL blocks, this figure may increase to 20% or more.

System emulators tend to see very large gains from dynamic translation due to peephole optimization of instruction blocks and execution of said blocks to decrease overhead interrupt processing and multi-processor synchronization.

> I'm thinking about doing dead flag removal as well, but I have the feeling it
> might not make much of a difference when doing it in java since these kinds of
> things are typically those things that HotSpot should be very good at.

That depends. I'm not sure which phase dead code elimination is performed in the Java environment when JIT is used. You are using EBCL to emit Java bytecode directly. Unless Hotspot is known to do dead code elimination, I would expect the java compiler to do the dead code elimination. If that is the case then you wouldn't get the benefit of dead code elimination when using EBCL unless it has a similar feature.

> Does anybody have experience with this, and especially using java? Is there some
> good documentation somewhere about dynarec techniques that I should be aware
> about? Thoughts, suggestions?

The best sources on the subject tend to be academic research papers published through ACM and IEEE. As Bart mentioned, there is also the dynarec mailing list.

Dynamic recompilers are really not all that complex and when used in emulators, the process stays mostly the same. Basic blocks or "super" blocks of instructions are converted to an intermediate representation. Peephole optimizations are performed the IR nodes, including constant folding, constant propagation, inlining and dead code elimination. The compiled block is cached and is then executed whenever encountered in the future. Interrupts are always processed between block executions. Thats pretty much it. Everything else tends to be influenced by the particular system being emulated and the types of programs being run. As an example, self-modifying code in a large address space will require some sort of paging scheme to do reasonably fine-grain code invalidation.


SubjectRe: Dynarec using java and BCEL new Reply to this message
Posted byerikduijs
Posted on08/03/04 03:32 PM



Thanks for your detailed reply :-)

"Unless Hotspot is known to do dead code elimination, I would expect the java compiler to do the dead code elimination. If that is the case then you wouldn't get the benefit of dead code elimination when using EBCL unless it has a similar feature."

HotSpot does perform dead code elimination on the fly, and various other agressive optimizations (see http://java.sun.com/javaone/javaone2001/pdfs/2696.pdf and
http://java.sun.com/products/hotspot/docs/whitepaper/Java_Hotspot_v1.4.1 /Java_HSpot_WP_v1.4.1_1002_4.html). So I guess we can just first not do any such optimizations ourselves and see how HotSpot will perform.




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode