Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (592)
Games in Android Showcase (168)
games submitted by our members
Games in WIP (646)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 6 7 [8] 9 10
 71 
 on: 2015-06-30 10:00:57 
Started by basil_ - Last post by nsigma
i do cos i'm running into
OutOfMemoryError
s (after creating thousands of short-living threads) and try to fix it.
Forgive me if i seem like I'm being a pain.  How are thousands of short-lived threads being created?

For thread read Thread.  This issue is caused by the creation of thousands of Thread objects that proxy the same (or a few) native threads.

 72 
 on: 2015-06-30 09:58:06 
Started by basil_ - Last post by Roquen
i do cos i'm running into
OutOfMemoryError
s (after creating thousands of short-living threads) and try to fix it.
Forgive me if i seem like I'm being a pain.  How are thousands of short-lived threads being created?

 73 
 on: 2015-06-30 09:52:21 
Started by basil_ - Last post by nsigma
TL;DR - switch to using JNA  Wink

OK, I did a load of research to help fix this issue in JNA.  This now uses thread-local storage (pthread_key_create or TlsAlloc) to cache a reference to the JNI info for an attaching thread, and makes use of the TLS destructor to detach the thread from the JVM just before the thread dies.  This behaviour isn't JNA default, but has to be requested - I did some work on it because of a similar issue in binding to a native audio library (JACK audio server <> JNAJack)

JNA code for this is included in here - https://github.com/twall/jna/blob/master/native/callback.c

Incidentally, the complexity of that code is one reason I'm quite in favour of projects like JNA - fix the problem in one cross-platform library rather than many!

@trollwarrior1 mentioned Android - if this is just for Android then it's easier because you don't have to handle the Windows side and pthread TLS is simpler.  This is mentioned in the Android docs (last paragraph) - http://developer.android.com/training/articles/perf-jni.html#threads

btw - the Thread objects created are very lightweight.  On desktop I did some benchmarking, but while there was a significant performance hit with audio in JNAJack, there was minimal with video in GStreamer-Java - but there's the difference between 24fps and 600+!

 74 
 on: 2015-06-30 09:15:57 
Started by basil_ - Last post by basil_
yes, java should not care about that at all.  i do cos i'm running into
OutOfMemoryError
s (after creating thousands of short-living threads) and try to fix it.

again, deattaching the JNIEnv disposes the java-thread, just as expected. not in the case of
ARBDebugOutput
- where i do not know if its callback are really executed in a extra native thread. attaching multiple times increments a counter ?

in the case of fmod, the threads are just "normal" threads like pthread_t on Linux etc. or HANDLE's on win32, nothing fancy. running in the background, calling functions (which eventually end up calling a java methods).

 75 
 on: 2015-06-30 08:56:45 
Started by steg90 - Last post by steg90
Cheers Jesse,

Couldn't have done it without your help!

Looking to do some lighting next...not sure of which way to go with this though, looked at using a shader.

Thanks

 76 
 on: 2015-06-30 08:45:41 
Started by basil_ - Last post by Roquen
Aside: don't know fmod, but it seems like the java side would only need to know about 1 thread...the one it interacts with.

 77 
 on: 2015-06-30 08:28:17 
Started by CommanderKeith - Last post by CommanderKeith
Thanks for your comments, very interesting.

Google is wrong because they knew about Java ME and that companies are supposed to pay royalties for mobile development.
Why are companies supposed to pay royalties for mobile development? It seems that is the Apple model, but it's certainly against consumers' interests and the anti-trust pro-competition legal framework. Also, Java ME was a flagging under-invested framework that was dying. It was only a matter of time before it was going to be replaced.

Oracle hasn't won the fight yet but unfortunately they are on their way to success. As part of the JCP EC I know of the hard confrontations...
If you don't mind me asking, what's your involvement in the JCP EC?

Apparently the case has become political, with the US government weighing in and asking the court not to accept Google's appeal. I'm not a lawyer, but to my knowledge, if an appeal is refused then Google can't escalate the matter and therefore has to accept the last (unfavourable) judgement.

From that Reuters article:
Quote
The Obama administration, which was asked to weigh in on the issue earlier this year, asked the Supreme Court not to take the case. The administration said the dispute had raised important concerns about the effect that enforcement of Oracle's copyright could have on software development, but said those issues could be addressed via Google's fair use defense.

 78 
 on: 2015-06-30 08:10:19 
Started by basil_ - Last post by basil_
aye, this is similar to how i use it now. in your andriod projects, do you use
DetachCurrentThread
at some point ?

yes, i'm very sure attaching spawns a new thread. not if i do not detach at the end.  seems like the AttachCurrentThread is about the current-c-thread, not the java one.

to be extra sure i track the thread id's on both sides :

works for windows :
1  
2  
3  
4  
5  
6  
7  
8  
#ifdef WIN32
#include <windows.h>
unsigned long currentThreadID()
{
  return (unsigned long)GetCurrentThreadId();
}
#else
[...]


and then, setting the java thread name when attaching :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
if( env_status == JNI_EDETACHED )
{
  JavaVMAttachArgs args;

  args.version = JNI_VERSION_1_6;
  args.group = NULL;

  char str[256];
  sprintf(str, "jni-attached-daemon-%lu", currentThreadID());

  args.name  = str;

  (*jvm)->AttachCurrentThreadAsDaemon(jvm, (void **)&env, &args);

   *attached = 1;
}


now on the java side i see lots of threads with the same name - matching what sprintf() does.
i use
Thread.enumerate(Thread tarray[])
or the keys from
Thread.getAllStackTraces()
to list the java threads.


 79 
 on: 2015-06-30 06:33:51 
Started by shadowstryker - Last post by vbrain
I'm working on Pezna Story Engine.
I'm making great progress on it. The hardest part is done. I'd say it's about 50% complete.

 80 
 on: 2015-06-30 06:10:50 
Started by CommanderKeith - Last post by noctarius
Oracle hasn't won the fight yet but unfortunately they are on their way to success. As part of the JCP EC I know of the hard confrontations and my point of view is that both sides are wrong. Oracle is wrong to start a fight over API copyrights and nobody can tell me they're not aware of the problems a win would bring for the whole industry and Google is wrong because they knew about Java ME and that companies are supposed to pay royalties for mobile development. Even though Google chose to use the Java SE APIs it is more like a twofold way to work around this issue, first of all using "open-sourced" APIs and secondly not using Java ME.

Oracle wants a piece of the Android mobile market, my view again, and I totally understand their point here. Google and Oracle should find a solution which doesn't make APIs copyrightable and I really hope that the court is not as dumb as I might imagine them. My gut feeling for such lawsuits is that you most often have judges that have no idea of the industry and the implications that arise from their "views".

Pages: 1 ... 6 7 [8] 9 10
 
deepthought (24 views)
2015-06-30 15:39:44

deepthought (26 views)
2015-06-30 15:39:09

deepthought (33 views)
2015-06-30 15:36:52

Za\'Anzabar (21 views)
2015-06-29 05:44:54

TritonDreyja (36 views)
2015-06-24 17:10:40

CopyableCougar4 (33 views)
2015-06-23 00:34:45

BurntPizza (37 views)
2015-06-21 20:36:46

cookiecompiler (80 views)
2015-06-11 15:42:53

cookiecompiler (44 views)
2015-06-11 15:41:14

NegativeZero (72 views)
2015-06-11 09:49:18
How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14
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!