--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/5d9d48bfb6c3f80bcb0787a49f70d2cad24f2ec6.camel%40doppel-helix.eu.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/6e4c70fa4038f3e543766085b7755acb95a1c820.camel%40doppel-helix.eu.
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/5a122cc7cfe692a49aba9e6749b8a6dda55b3b49.camel%40doppel-helix.eu.
> Early on with no pressure on the heap, this isn't a problem as GC is delayed, but when heap limited, GC is more aggressive and I would guess tries to free larger allocations first.
Don’t even guess, switch on GC tracing and look at the traces.
For any OpenJDK-based JVM since 1.5, you have a copying collector.
Copying collectors never touch unreachable objects, they just ignore them and copy the reachable ones.
Now OpenJDK got a ton of detail optimization since 1.5 (and it wasn’t half bad even in 1.5), and I recall having seen that there’s some special treatment for “humongous” blocks; my assumption that unreachable large blocks don’t get any special treatment may be wrong as well ;-)
Regards,
Jo
Sensitivity: C2 Internal
The content of this e-mail is intended only for the
confidential use of the person addressed.
If you are not the intended
recipient, please notify the sender and delete this e-mail immediately.
Thank
you.
Given I’m a developer busy with a day job and supporting open source in my spare time, not having the equipment to reproduce this myself, and relying on the goodwill of users to do enough logging for me to try to identify the problem, this seems overkill.
But if you’d like to try to reproduce the problem and trace it to confirm my guess, I’d love the input!
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/DB6PR0102MB2725A15B219F794B867CD308B96F9%40DB6PR0102MB2725.eurprd01.prod.exchangelabs.com.
Heh. Sorry. That was just a comment from the peanut gallery.
Same situation for me :-)
All I wanted to say that you shouldn’t base decisions on assumptions what GC is doing, that’s risky.
I’m not saying it’s important for the topic at hand :-)
Sensitivity: C2 Internal
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/A8E4E9B1-E37F-43D9-9206-FC305D2CB2B5%40gmail.com.
All good.
I’m only really guessing at the symptoms. But tracing through the code and identifying where references are lost are more deterministic ways of fixing it, which is what I tried to do, and Matthias did much better than I did!
I do appreciate the advice and wouldn’t be surprised if I end up using it for some other problem in the future.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/DB6PR0102MB27250826799C5022770047AAB96F9%40DB6PR0102MB2725.eurprd01.prod.exchangelabs.com.
OK, I'm still confused here.
Our fix(es) are based on the idea that the variable "user" has gone out of scope in this line because we’re passing on a reference not attached to “user”:
return getAccountBySid(user.User.Sid);
Initially I thought this was associated with the method "ending" with the return call, like tail recursion. However, as I've read more, Java does not do any optimization for tail recursion and every reference I see indicates scope lasts until the trailing curly brace. I wrote this test class which seems to confirm the variable is still in scope throughout the return call:
public class Test {
static boolean bar = false;
static Foo foo = null;
static class Foo {
public int baz = 42;
public Foo() {
bar = true;
}
@Override
protected void finalize() {
bar = false;
}
}
static boolean scopeTest() {
foo = new Foo();
System.out.println("Foo is " + foo + ", bar is " + bar);
return tailCall(foo.baz);
}
private static boolean tailCall(int baz) {
// has the scopeTest() method ended yet?
System.gc();
System.gc();
Util.sleep(2000);
System.gc();
System.gc();
System.out.println("Foo is " + foo + ", bar is " + bar);
return bar;
}
public static void main(String[] args) {
scopeTest();
}
}
So despite our “fixes” apparently working, I still don’t understand exactly why Memory is losing the allocation in the return statement.
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/a2fee5e0b535128e3649e74e6c94ea121b85a031.camel%40doppel-helix.eu.
Uh, ignore that. By making foo static it’s always, forever, in scope. Doh!
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/a2fee5e0b535128e3649e74e6c94ea121b85a031.camel%40doppel-helix.eu.
OK, same question, with a better example. I don’t see Foo going out of scope, which should trigger the finalize to switch bar back to false.
Output:
After instantiation, bar is true
After finalize, bar is false
Before call, bar is true
During call bar is true
After call bar is true
Code:
public class Test {
static boolean bar = false;
static class Foo {
public int baz = 42;
public Foo() {
bar = true;
}
@Override
protected void finalize() {
bar = false;
}
}
static boolean scopeTest() {
Foo foo = new Foo();
System.out.println("After instantiation, bar is " + bar);
foo = null;
System.gc();
System.gc();
Util.sleep(2000);
System.out.println("After finalize, bar is " + bar);
foo = new Foo();
System.out.println("Before call, bar is " + bar);
return tailCall(foo.baz);
}
private static boolean tailCall(int baz) {
// has the scopeTest() method ended yet?
System.gc();
System.gc();
Util.sleep(2000);
System.gc();
System.gc();
System.out.println("During call bar is " + bar);
return bar;
}
public static void main(String[] args) {
System.out.println("After call bar is " + scopeTest());
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/a2fee5e0b535128e3649e74e6c94ea121b85a031.camel%40doppel-helix.eu.
OK, I'm still confused here.
Our fix(es) are based on the idea that the variable "user" has gone out of scope in this line because we’re passing on a reference not attached to “user”:
return getAccountBySid(user.User.Sid);
Initially I thought this was associated with the method "ending" with the return call, like tail recursion. However, as I've read more, Java does not do any optimization for tail recursion and every reference I see indicates scope lasts until the trailing curly brace. I wrote this test class which seems to confirm the variable is still in scope throughout the return call:
Going out of scope does not necessarily trigger finalization.
Actually, finalization may never run at all. It’s purely advisory; if you want any guarantees, you need other mechanisms, and even these aren’t guaranteed to be run at any particular point in time.
If you wish to guarantee that a specific action is run, you have to call it from normal code.
If you wish to run it when going out of scope, your only (and actually quite good) option is try-with-resources.
Regards,
Jo
Sensitivity: C2 Internal
From: jna-...@googlegroups.com <jna-...@googlegroups.com> On Behalf Of Daniel Widdis
Sent: Sonntag, 14. März 2021 18:50
To: jna-...@googlegroups.com
To view this discussion on the web visit https://groups.google.com/d/msgid/jna-users/5C7CF744-355D-4021-886D-FEE952356989%40gmail.com.