java-memory-model

What is in java object header

别等时光非礼了梦想. 提交于 2019-12-17 02:31:36
问题 Could you give me some information on what is exactly stored in object header? I know, that it's probably JVM dependent, but maybe for HotSpot at least? I'm looking for exact description specifically for a first row. I've read several information that I can't verify positively with information I find. Maybe you have a link to OpenJDK wiki that says it all? 回答1: For HotSpot: The object header consists of a mark word and a klass pointer. The mark word has word size ( 4 byte on 32 bit

java set max stack size

笑着哭i 提交于 2019-12-13 06:29:31
问题 How can I set maximum stack size? I use jEdit to search with regular expression in rather big file (73 kb) and it fails with StackOverflowException. I tried to set -Xss40m but it seems to be initial stack size and after some time it fails with following exception 11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0: Exception in thread "AWT-EventQueue-0" 11:45:31 AM [AWT-EventQueue-0] [error] AWT-EventQueue-0: java.lang.OutOfMemoryError: unable to create new native thread 11:45:31 AM [AWT

Does static provide additional guaranties in JMM context?

我与影子孤独终老i 提交于 2019-12-13 03:20:42
问题 I am reading about java singleton and I've met strange things. I will refer to following artice as example(you can easy find more) Author provides the following singleton: public class ASingleton { private static ASingleton instance = new ASingleton(); private ASingleton() { } public static ASingleton getInstance() { return instance; } } and comments: Pros: - Thread safety without synchronization - Easy to implement Cons: - Early creation of resource that might not be used in the application.

Java Concurrency - Publishing Immutable Objects (Java Concurrency In Practice)

微笑、不失礼 提交于 2019-12-12 07:22:28
问题 In Java Concurrency In Practice, the author stated that Immutable objects can be published through any mechanism Immutable objects can be used safely by any thread without additional synchronization, even when synchronization is not used to publish them. Does it mean that the following idioms are safe to publish immutable objects? public static List<ImmutableObject> list = new ArrayList<ImmutableObject>(); // thread A invokes this method first public static void methodA () { list.add(new

Executor.execute() JMM guarantee

白昼怎懂夜的黑 提交于 2019-12-12 02:09:21
问题 Consider the following code snipet: public class A { private final Executor executor = Executors.newCachedThreadPool(); private final Queue<Object> messageQueue = new ConcurrentLinkedQueue<M>(); public void sendMessage(Object message) { messageQueue.offer(message); executor.execute(new Runnable() { @Override public void run() { final Object message = messageQueue.poll(); // Can message == null? } }); } } Is it guaranteed that messageQueue contains the message by the time when the Runnable

Maximum BackStack size in android

天大地大妈咪最大 提交于 2019-12-11 02:22:21
问题 I'm a new one to android development. I need to know the Maximum memory Size of BackStack in android And i want to know How many activities of Android Application can be stored in BackStack Thanks 回答1: The maximum memory size of your back stack is the same as the amount of free memory on your device. You can keep throwing things on the activity stack until you get an OutOfMemoryException. Check this 来源: https://stackoverflow.com/questions/16211279/maximum-backstack-size-in-android

What makes immutable objects to be published without safe publication techniques?

最后都变了- 提交于 2019-12-10 21:24:30
问题 What does it mean to say that immutable objects can be published even without resorting to safe publication idioms? I have read Java Concurrency in Practice ( Chapter 3 , Sharing Objects ) but still not able to comprehend the statement : Immutable objects can be published through any mechanism. V/S Effectively immutable objects should be safely published. Edit: I have been through a similar question on SO and the answers but still unable to understand how immutable objects can be published

Sequential consistency volatile explanation

落爺英雄遲暮 提交于 2019-12-10 10:09:00
问题 I am watching video from java jpoint conference. I have question about following slide from Alexey Shipilev report: Excuse me for non-english on slide. Actually author says that it is impossible that variable set will be r1 = 1 (Y) r2 = 0 (x) r3 = 1 (x) r4 = 0 (Y) According the video he implies that it is obviously. Can someone clarify why this value set impossible according JMM? P.S. If I understand Alexey notation correct it respects the following code: public class SequentialConsistency {

Does this example contain a data race?

泪湿孤枕 提交于 2019-12-10 09:59:17
问题 Here is the originan question, but mine have some differences with it. C++ memory model - does this example contain a data race? My question: //CODE-1: initially, x == 0 and y == 0 if (x) y++; // pthread 1 if (y) x++; // pthread 2 Note: the code above is written in C, not C++ (without a memory model). So does it contain a data race? From my point of view: if we view the code in Sequential Consistency memory model, there is no data race because x and y will never be both non-zero at the same

How much -XX:MaxPermSize size i can mention for 4GB and 8GB Ram and calculation for this?

纵然是瞬间 提交于 2019-12-08 05:13:13
问题 How much -XX:MaxPermSize size i can mention for 4GB and 8GB Ram. Here are the other detalis of my system OS:-window XP(32 bit) RAM:-4 GB java_opt- -Xms1536m -Xmx1536m //(mentioned as environment variable): tomcat version:-6.0.26 I have another system with 8GB ram with other details exactly same . Yes os is 64 bit Window 7. Along with this also let me know what can be the max value for -Xmx parameter for both the systems? It would be great if some body can tell me the calculation to arrive at