Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Jack, Java bytecode -> C++ [Updated to be more descriptive]  (Read 8515 times)
0 Members and 1 Guest are viewing this topic.
Offline badlogicgames
« Posted 2012-09-03 23:50:10 »

https://github.com/badlogic/jack

Jack is a silly attempt to write a Java bytecode to C++ transpiler to allow ahead of time compilation of Java apps. I intend to use it to target platforms that don't have a JVM or other restrictions, e.g. iOS, consoles etc.

Goals:
- Java 1.5 language compatibility
- reflection
- exceptions
- covariant return types (needed for generics)
- threading
- JNI and a custom native interface to ease wrapping C/C++ apis.
- minimal runtime library ala Avian VM
- debuggable (preserve class hierarchy, field and method names, inline Java source as comments for readability)

Non-Goals:
- run Eclipse
- Swing/AWT/EE support
- runtime bytecode loading
- full java memory model

Done
- translation of class hierarchy (that was no fun...)
- translation of method bodies (surprisingly simple)
- ordered class initialization (differs from JVM on the fly class initialization)
- GC (via Boehm GC for now)
- covariant return types
- basic class descriptors (instanceof etc., C++ dynamic_cast doesn't quite cut it)
- String literals (they need special care...)
- Arrays (since they are special case in many respects)
- incremental compilation, so C++ compile times are quick as well.
- compiles the first iteration of the runtime library, ~220 classes.

Todo
- exceptions
- full reflection support
- threading & monitors
- JNI & custom native interface
- more work on the runtime library

I have a plan for each Todo and am confident that this can be realized within a reasonable time-frame.

I'd love to get input on what you guys thing the runtime library should contain at a minimum. I want to focus on things relevant to game development. The runtime can be extended later on, be it by including OpenJDK or devising custom runtime classes. I'd be in favor of keeping it simple.

Feedback welcome, if you fork it and want to contribute i'd be even happier. Note the disclaimer at the top of the README Smiley

http://www.badlogicgames.com - musings on Android and Java game development
Offline ReBirth
« Reply #1 - Posted 2012-09-04 03:26:10 »

Ah I have seen this before on random browsing session. Any current running/published project using this?

Offline kaffiene
« Reply #2 - Posted 2012-09-04 04:31:15 »

If you wanted to use this to target a java game using JOGL or LWJGL for iOS, how would that work?  I'm specifically wondering about how the graphics coding would look.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2012-09-04 09:39:12 »

Hopefully just straight LWJGL code Smiley LWJGL would need a specific iOS port of course.

The higher agenda is libgdx of course but it'd have to start with a LWJGL port in the first place.

Also you'll be needing a wrapper for touch input and some extra APIs for specific iOS functions and requirements.

Anyway, I'm looking forward to seeing what comes out of this. Hopefully a fully-compliant Java 7 core with annotations and everything all working as expected. Of particular importance to me is a binary compatible ObjectInputStream/ObjectOutputStream. Also I think you might need to ditch Boehm at some point, bite the bullet and go fully accurate compacting GC.

Cas Smiley

Offline Roquen
« Reply #4 - Posted 2012-09-04 09:48:53 »

I'd just start with a naive semi-space GC and revisit if everything else more-or-less works.  Real GC is a real PITA.
Offline badlogicgames
« Reply #5 - Posted 2012-09-04 09:55:06 »

Riven already created a nice GC implementation in Java. Thankfully he left out all the nitty gritty details, like getting registers and the stack in order on rewrites, blocking threads etc. Riven doesn't like C++ much.

Unity uses Mono, which in turn uses either Boehm or their own sGen GC. Looks like Boehm was good enough, even on mobile.

Also, who uses Java serialization?

http://www.badlogicgames.com - musings on Android and Java game development
Offline Roquen
« Reply #6 - Posted 2012-09-04 10:10:25 »

More food for thought on GC is checking out the JikesVM source.  Did I mention that this is insanely ambitious?  This isn't a project I'd attempt unless someone was throwing insane amounts of money at me.
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2012-09-04 10:29:04 »

You can get surprsingly far without a vast amount of effort.

Boehm's good enough on mobile... if you don't rely on it working properly, which is unfortunate, because it means you practically daren't rely on it at all. So what everyone does is make lots of pools and never allocate or deallocate anything if they can help it, which kinda makes a mockery of the way things should work in Java. Not only that but in C#, devs make heavy use of structs instead of relying on ordinary heap objects. Food for thought. Riven's GC is a good start, algorithmically; the remaining parts of the implementation I'm sure you could mostly figure out. Don't forget that in the context of games programming it is enough to have a GC that runs in a reliably short amount of time every single frame when System.gc() is called - so factor that into your optimisations. I'd rather have a constant 3ms spent on GC every frame than randomly getting 100ms delays. Or worse, regularly getting 100ms delays.

I use Java serialization extensively - it makes a remarkably efficient way of configuring game data without having to write anything much manually or parse stupid files at startup (==slow). It is also super-effective at managing save/load games and hibernating application state (something iOS really really really needs you to do right). That's why you need to support it Smiley

Cas Smiley

Offline Nate

JGO Kernel


Medals: 147
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #8 - Posted 2012-09-04 12:15:18 »

I use Java serialization extensively - it makes a remarkably efficient way of configuring game data without having to write anything much manually or parse stupid files at startup (==slow). It is also super-effective at managing save/load games and hibernating application state (something iOS really really really needs you to do right). That's why you need to support it Smiley
There are much better ways to do the same job.  Yawn

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2012-09-04 12:38:34 »

Actually, no there aren't.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #10 - Posted 2012-09-04 13:13:45 »

There are much better ways to do the same job.  Yawn

Actually, no there aren't.

Let's hear it boys, Serialization is relevant to our interest.


@topic, I guess Jack is not used right now for the upcoming iOS libgdx backend ? since you guys said its almost done, only audio and something to do

Offline badlogicgames
« Reply #11 - Posted 2012-09-04 13:31:20 »

We are currently using.MonoTouch and IKVM. That backend is almost complete. Jack should be used for an alternative backend that won't cost money, or at least not 400$ such as a MonoTouch license.

http://www.badlogicgames.com - musings on Android and Java game development
Offline Cero
« Reply #12 - Posted 2012-09-04 13:47:53 »

We are currently using.MonoTouch and IKVM. That backend is almost complete. Jack should be used for an alternative backend that won't cost money, or at least not 400$ such as a MonoTouch license.

Well I wasn't aware that the current iOS backend would involve such a cost per developer. Obviously we dont have that kinda money, and even if we did, I would only spend that if I was sure of success...

Meaning I would wait for Jack aswell.
Besides the fact that I think every java to C++/native code attempt is good, because we already do so much to hide java and make it work without java problems (private jre and whatnot)

Btw I'm using JNA for gStreamer actually... would that work ?

Offline badlogicgames
« Reply #13 - Posted 2012-09-04 15:20:11 »

I'd have to look ibto JNA but my gut feeling tells me it's doing funky things. Would you use gstreamer on iOS?

http://www.badlogicgames.com - musings on Android and Java game development
Offline Cero
« Reply #14 - Posted 2012-09-04 15:29:28 »

I'd have to look ibto JNA but my gut feeling tells me it's doing funky things. Would you use gstreamer on iOS?

Well that was just out of curiosity if I were to convert my java code to C++ for a desktop game.
Of course not needed for iOS - for that I just use libgdx features.

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #15 - Posted 2012-09-04 17:07:05 »

Riven already created a nice GC implementation in Java. Thankfully he left out all the nitty gritty details, like getting registers and the stack in order on rewrites, blocking threads etc. Riven doesn't like C++ much.
Ahh, the sense of being valued for spending hours explaining how Jack could be implemented, explaining GC strategies and writing a mockup implementation, currently met with a mixture of sarcasm, insinuations and compliments, never really wears off. It's a gift, really, to deal with that emotionally. I'm awesome like that!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline badlogicgames
« Reply #16 - Posted 2012-09-04 17:20:43 »

you are my butt buddy!

http://www.badlogicgames.com - musings on Android and Java game development
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #17 - Posted 2012-09-04 17:59:51 »

This must be some new internet slang for an ersatz homosexual co-dependent abusive relationship.

I shall patiently wait until Titan Attacks runs in native code and then rejoice.

Cas Smiley

Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #18 - Posted 2012-09-04 21:17:25 »

Actually, no there aren't.

Cas Smiley
Cas, I think Nate was subtly hinting that Kryo could do a better job than plain old Java Serialization Grin

you are my butt buddy!
NO HE'S MINE! Angry

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #19 - Posted 2012-09-04 22:22:48 »

Ahh I didn't make the connection.
I'm sure Kryo's great, it's just not as simple as ... implements Serializable { ...

Cas Smiley

Offline badlogicgames
« Reply #20 - Posted 2012-09-04 23:14:38 »

I spent the night refactoring the monolithic mess i created over the last couple of days into a mostly sane code base. If someone wants to join the effort let me know. The code should be quite straight forward for the most part. The following things could be areas a contributor can work on:

- exceptions
- CNI like Java->native/native->Java communication (see http://gcc.gnu.org/onlinedocs/gcj/About-CNI.html)
- threading
- reflection

exceptions should be the simplest task, followed by basic reflection, CNI and threading. Another area i'm sure nobody will want to help out is porting unit tests from other VMs over, e.g. Avian's small test suite.

http://www.badlogicgames.com - musings on Android and Java game development
Offline badlogicgames
« Reply #21 - Posted 2012-09-04 23:41:38 »

I updated the README with instructions and a basic code overview, see https://github.com/badlogic/jack/blob/master/README.md

http://www.badlogicgames.com - musings on Android and Java game development
Offline Nate

JGO Kernel


Medals: 147
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #22 - Posted 2012-09-05 01:00:03 »

Ahh I didn't make the connection.
I'm sure Kryo's great, it's just not as simple as ... implements Serializable { ...
You are right, it is simpler. You don't need to implement any interface. The Json class in libgdx or the jsonbeans lib outside libgdx is also simpler, just give it POJOs, done. But I understand change is scary, you know, for old people. Smiley

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #23 - Posted 2012-09-05 09:16:51 »

(Split the topic to avoid Jack thread derailment)

Cas Smiley

Offline jezek2
« Reply #24 - Posted 2012-09-05 11:35:46 »

Having better GC is quite problem with this simple approach of cross-compiling to other language. For fast accurate GC you need cooperation with the compiler so you know the format of stack and register usage with regard to references (by having extra info about these on certain code points).

You can sidestep that by having second (shadow) stack used just for references where you know exactly it's format, for references held in registers it would be sufficient to just maintain the reference on the second stack (can be little imprecise, but never having reference in register that isn't in the stack) while it's used in registers. This incurs some speed penalty, but is probably the fastest solution.

Other alternative is to use reference counting with cycle detector (could be called manually at "safe" points in application). This would be slowest, esp. because of need of atomic updates for the reference counter for multithread usage.

Maybe some semi-manual approach (similar to real time java) would be preferrable instead of GC.
Offline badlogicgames
« Reply #25 - Posted 2012-09-05 11:56:07 »

The problem with a shadow stack is, that if i have a copying GC, i still need to reset the registers, as they'd contained the old address of the object. So, whatever i do, i have to have some platform specific code that checks/rewrites the registers as well. Adding in multi-core, this can get really messy.

Another approach would be to scan the stack and registers conservatively (scanning the stack is almost simple, scanning the registers could be done by dumping them into a jmp_buff via setjmp). The GC would then only rewrite objects that are not on the stack/registers, while still knowing about all the references that are live.

Boehm GC works so far, and i guess i'll wait with improving the GC until the other things on the task list are (mostly) finished.

Thanks for the input!

http://www.badlogicgames.com - musings on Android and Java game development
Offline Roquen
« Reply #26 - Posted 2012-09-05 14:23:25 »

You could always be evil and use an object table instead.  Yeah that would be slow (and I'm just pulling this out of my butt, so I'm probably missing something obvious).
Offline kaffiene
« Reply #27 - Posted 2012-09-06 04:47:41 »

I'd assume that using the Boehm GC, Weak, Soft and Phantom references wouldn't be easy (or even possible?) to implement?

The reason I ask is that I like Soft references for caching.
Offline badlogicgames
« Reply #28 - Posted 2012-09-06 06:32:55 »

Soft/Weak/Phantom references are possible with Boehm GC.

http://www.badlogicgames.com - musings on Android and Java game development
Offline Sickan

Senior Member


Medals: 9



« Reply #29 - Posted 2012-09-06 12:16:11 »

I never really understood why you would actually need a garbage collector or do memory management. I suppose I might be misguided, but couldn't one just garbage collect everything at the end of the current block, i.e when the object occupying the memory goes out of scope.
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (14 views)
2014-09-19 03:14:18

Dwinin (32 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (80 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (31 views)
2014-09-07 01:12:14

Longarmx (37 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!