Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 8650 times)
0 Members and 1 Guest are viewing this topic.
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #30 - Posted 2012-09-06 13:20:49 »

@Sickan methinks you need to read up about how heaps, threads and escape analysis work.

Cas Smiley

Offline Roquen
« Reply #31 - Posted 2012-09-06 13:23:09 »

Simple example:  while(true) { x = new Foo(); x.something(); }
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #32 - Posted 2012-09-06 13:29:45 »

And for Sickan's benefit:

It is not apparent from the code that Roquen just posted whether the construction of a Foo() or calling .something() places a reference to that Foo somewhere else. For example in the constructor of Foo:
1  
2  
3  
Foo() {
    addFooToSomeListElsewhere(this);
}


So you need something called escape analysis to analyse the scope between the while { and } to see if any reference to that Foo actually escapes outside of it. If it does - or if the stack is full - it's got to go on the heap. If not - it's a candidate for on-stack replacement, or at the very least, some sort of quick heap reclamation trick.

Escape analysis is very fast, operating in linear time I'm told; and can be run on ever expanding scopes depending on how far you want to take it. In theory you could end up with the entire heap allocated on the stack if your code fits well enough.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline badlogicgames
« Reply #33 - Posted 2012-09-06 14:23:29 »

Escape analysis breaks down as soon as unsafe operations are involved, e.g. JNI, reflection etc. There are ways around this, but i'm not sure i have the jedi powers to pull that off Smiley conservatively allocating some things on the stack could work though.

http://www.badlogicgames.com - musings on Android and Java game development
Offline Cero
« Reply #34 - Posted 2012-09-06 14:40:38 »

Well if you write a C++ game and dont use any pre-done GC implementation, which I think many people do, because GC's get a lot of hate, you do have to do it all yourself then...

Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #35 - Posted 2012-09-06 16:01:24 »

Escape analysis breaks down as soon as unsafe operations are involved, e.g. JNI, reflection etc. There are ways around this, but i'm not sure i have the jedi powers to pull that off Smiley conservatively allocating some things on the stack could work though.
Well, you keep those bits of code to an absolute minimum then. Which you do. So no problem there.

Cas Smiley

Offline Best Username Ever

Junior Duke





« Reply #36 - Posted 2012-09-08 03:45:23 »

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.

You can do that for some variables, but not all of them. The trick is knowing when you can do that. Some references may be shared with other sections of code. If those references get deleted then the second section of code that still contains a reference to the deleted objects won't have access to them anymore. You can use escape analysis to determine ahead of time which objects are safe to delete and which ones are not. Those that don't escape can be stored on the stack (or a stack, but normally it's combined with the call stack used to determine where functions resume after return statements). When the call stack unwinds, the stack space allocated for those objects can be freed at the same time. For objects that may need to stick around longer than the function scope, then those are allocated on the heap (shared memory space.)

[size=smaller]It's slightly off topic, but - just in case you're asking because you read something from a C++ website - sometimes garbage collectors have a time advantage over scope triggered destructor memory management patterns and almost always have an advantage over reference counting. The overhead of memory management may be large enough for single objects that it's slower to delete only one at a time. You can budget time to delete and dispose objects in batches and actually use less time overall. It's also misunderstood that reference counting and scope based destructor behavior provides better real time characteristics. Some programs could create chain reactions that could stall the program longer than a real time garbage collector would.[/size]



Escape analysis is very fast, operating in linear time I'm told; and can be run on ever expanding scopes depending on how far you want to take it. In theory you could end up with the entire heap allocated on the stack if your code fits well enough.

What do you mean by linear time? Can't you do good escape analysis at compile time? Stack allocation takes constant time. And unless you're interpreting code on the fly, then I can't imagine what time efficiency you're referring to. The analysis is probably fast and only needs to be done once.
Offline Roquen
« Reply #37 - Posted 2012-09-08 06:22:07 »

You can only do escape analysis at compile time if you have enforcing contracts (in a dynamic language).
Offline badlogicgames
« Reply #38 - Posted 2012-09-08 08:46:18 »

Wrote about my motivation, anyone please double check and tell me whether i should give up. Oracle seems to have a plan as well at least for iOS.

http://www.badlogicgames.com/wordpress/?p=2583

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

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #39 - Posted 2012-09-08 17:11:59 »

I have done a lot of research on this subject as well, but free alternatives to span both Android and iPhone just don't exist without a price. Jack is a breath of fresh air, but I understand the amount of effort it'll take to change Java byte-code to C would be grueling. On the other side of the coin, you will learn so much about Java byte-code that it'll probably make libGDX a lot better in the long run.

To be honest, since you are doing this as a learning experience/hobby, I would suggest not giving up on it. Especially since we have no clue whether or when Oracle will be able to complete the port to iOS. Given the security breaches that we are getting already, they are putting themselves in a bad position when it comes to porting Java anywhere. They have to work on fixing the problems at hand first.

I am excited to see that someone cares enough to keep this idea of a free mobile port running. Even though many programmers are not speaking, there is a staggering amount of programmers that are waiting for something like this to emerge.


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Best Username Ever

Junior Duke





« Reply #40 - Posted 2012-09-08 18:31:59 »

Java seemed to be on a better trajectory when Sun was still around. I wouldn't want Oracle, Apple, and Google to be the only ones influencing the future. It sounds like your project has a lot of potential for spin off projects. Not just in Java, but also C++ and any language targeting JVM bytecode.
Offline gouessej
« Reply #41 - Posted 2012-09-08 19:40:11 »

Wrote about my motivation, anyone please double check and tell me whether i should give up. Oracle seems to have a plan as well at least for iOS.

http://www.badlogicgames.com/wordpress/?p=2583
Please don't give up. I agree with some things you wrote in your article about Avian and XMLVM.

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.

Longarmx (37 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!