From: Arno P. <ar...@pu...> - 2010-07-17 08:49:23
|
thanks for the patch, Paul. Can you please upload it to the review system? I promise a swift turnaround reviewing it. I would like to make some general comments without having looked at your patch. In your mail you refer to jvm:monitorenter. We want to deprecate the JVM instructions and move to the DEX instructions. But as far as I know, the DEX synchronization instructions are pretty much identical. I also wanted to say something about the associations. Panayotis has reported that they don't work in the simulator but do work on the actual device. Apparently you've implemented your own solution as a consequence. I would strongly advise against this. For one, it only matters if it works correctly on the device. I've heard many times that you cannot get around testing on the real device because of many subtle differences between the simulator and the device. So, we should optimize for the device; not the simulator. If the simulator version leaks memory, so be it. I'm sure Apple will fix that in the next version of the SDK. More importantly, I favor using the tools given to us by the SDK. Apple undoubtedly put a lot of effort on implementing these associations efficiently and rather than inventing our our mechanism, we should use theirs. So, to be honest, I am reluctant to commit your patch in its current form. Arno On 7/17/10 12:36 AM, Paul Poley wrote: > This is a pretty critical change, so please bare with me on the length > of this e-mail. > I have attached some source code that may be the best explanation. (See > TestSync.java specifically) > > The major points are: > > 1. Changing XMLVM's synchronization > 2. Implementing wait(), wait(long), notify(), notifyAll() > 3. Considering alternatives to associative references to store member > variables in java_lang_Object > > > In order to implement wait() and wait(long) in Objective-C, I must first > take more control of synchronization. > This is because these 2 methods release the Object's monitor for another > thread while waiting. > > So while @synchronized has been the perfect solution for > "jvm:monitorenter" and "jvm:monitorexit" before this point, it is not > longer sufficient because it is scope based. > I.e. I need to be able to release the Object's monitor for another > thread when calling wait() or wait(long) and then retain the monitor > again when the wait is over. > > My solution is to use NSLock, while accounting for exceptions and > recursive locks. > Java style, the following requires conversion: > > * synchronized (this) {* > * // Do something* > * }* > > It would be converted to: > > * acquireLockRecursive();* > * > * > * try {* > * // Do something* > * } finally {* > * releaseLockRecursive();* > * }* > > First every Object needs: > > * private NSLock myLock; // the lock which to use for the Object in > place of synchronizing on "this"* > * private int recursiveLocks = 0; // the number of recursive locks. > If only synchronized once, this is 1* > * private Thread owningThread; // the thread that owns the Object's > monitor or null for none* > > More in depth is: > > * private void acquireLockRecursive() {* > * boolean acquireLock = false;* > * synchronized (this) {* > * acquireLock = Thread.currentThread() != owningThread;* > * }* > * > * > * if (acquireLock) {* > * myLock.lock();* > * synchronized (this) {* > * owningThread = Thread.currentThread();* > * }* > * }* > * recursiveLocks++;* > * }* > * > * > * private void releaseLockRecursive() {* > * recursiveLocks--;* > * > * > * if (recursiveLocks == 0) {* > * synchronized (this) {* > * owningThread = null;* > * }* > * myLock.unlock();* > * }* > * }* > > Unfortunately, associative references do not work in the simulator, so I > do not believe this to be a viable option for member variables at this > point. > I don't think it would be prudent to stop allowing XMLVM to operate in > the simulator entirely. > Hopefully we can come up with a universal solution (maybe changing > java_lang_Object to inherit from NSObject instead of be one, but that > causes other issues). > > > I have attached the source code prototypes. For the current > conversation, see TestSync.java. In a later conversation, we can > discuss TestObject2.java. > I made a crude Java implementation of NSLock & NSConditionLock. They > work for this scenario, but are not intended for general use. > Also, note that they are backed by wait(), wait(long) & notifyAll(), > which is somewhat ironic since that's what we're trying to implement. > > > > Once all this is done, I can move on to wait() and wait(long) where they > can unlock() and lock() around the waiting period. > Please give me any input, positive or negative! If you disagree with > anything or everything, I would be interested in hearing those thoughts > as well. > > Thanks, > Paul Poley > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > > > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |
From: Panayotis K. <pan...@pa...> - 2010-07-17 14:35:37
|
17 Ιουλ 2010, 11:49 π.μ., ο/η Arno Puder <ar...@pu...> έγραψε: > > I also wanted to say something about the associations. Panayotis has > reported that they don't work in the simulator but do work on the actual > device. Apparently you've implemented your own solution as a > consequence. I would strongly advise against this. For one, it only > matters if it works correctly on the device. I've heard many times that > you cannot get around testing on the real device because of many subtle > differences between the simulator and the device. So, we should optimize > for the device; not the simulator. If the simulator version leaks > memory, so be it. I'm sure Apple will fix that in the next version of > the SDK. Just a quick note: The problem with associations in the simulator was in the previous version of the SDK. It is possible that with the release of 4.0 this is not the case any more. Right now I am practically away from my computer but I will have a look at it next week. |
From: Paul P. <bay...@gm...> - 2010-07-17 19:37:59
|
Hi Arno, I believe I have slightly misled you. My attached project in my earlier email is a Java proof of concept written with the intent ready to easily port to Objective-C. So it's not a patch just yet. I wanted to first make sure I wasn't going against the grain of the XMLVM community. Since it's all Java & not yet a patch, I have not implemented my own version of associative references. I agree that would be a poor approach & we should absolutely optimize for the device & not the simulator. My comments were mostly just pondering as to the best solution to that portion. If associative references work in the SDK4, then that's wonderful. I'm going to try that out this weekend. Regarding dex:monitor-enter vs jam:monitorenter, there's a comment saying "we can't map this to @synchronized {} because DEX may generate multiple monitor-exit for one monitor-enter". Other than that, it wouldn't seem very difficult to use the DEX instructions instead of JVM. I think we're in agreement. If everything goes smoothly, I will prepare a patch hopefully within the week. Hi Gergely, I took a look at your implementation. I believe we have come up with similar solutions. I used NSLock for synchronization (recursive conditions handled so that a single release can be called when needed for wait*) & NSConditionLock for wait* & notify*. Again assuming associative references work in SDK4, I will try to get our solutions together. Thanks! Paul Poley On Sat, Jul 17, 2010 at 9:36 AM, Panayotis Katsaloulis < pan...@pa...> wrote: > 17 Ιουλ 2010, 11:49 π.μ., ο/η Arno Puder <ar...@pu...> έγραψε: > > > > > I also wanted to say something about the associations. Panayotis has > > reported that they don't work in the simulator but do work on the actual > > device. Apparently you've implemented your own solution as a > > consequence. I would strongly advise against this. For one, it only > > matters if it works correctly on the device. I've heard many times that > > you cannot get around testing on the real device because of many subtle > > differences between the simulator and the device. So, we should optimize > > for the device; not the simulator. If the simulator version leaks > > memory, so be it. I'm sure Apple will fix that in the next version of > > the SDK. > > Just a quick note: > The problem with associations in the simulator was in the previous version > of the SDK. It is possible that with the release of 4.0 this is not the case > any more. Right now I am practically away from my computer but I will have a > look at it next week. > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > |
From: Panayotis K. <pan...@pa...> - 2010-07-18 22:47:46
|
On 17 Ιουλ 2010, at 5:36 μ.μ., Panayotis Katsaloulis wrote: > 17 Ιουλ 2010, 11:49 π.μ., ο/η Arno Puder <ar...@pu...> έγραψε: > >> >> I also wanted to say something about the associations. Panayotis has >> reported that they don't work in the simulator but do work on the actual >> device. Apparently you've implemented your own solution as a >> consequence. I would strongly advise against this. For one, it only >> matters if it works correctly on the device. I've heard many times that >> you cannot get around testing on the real device because of many subtle >> differences between the simulator and the device. So, we should optimize >> for the device; not the simulator. If the simulator version leaks >> memory, so be it. I'm sure Apple will fix that in the next version of >> the SDK. > > Just a quick note: > The problem with associations in the simulator was in the previous version of the SDK. It is possible that with the release of 4.0 this is not the case any more. Right now I am practically away from my computer but I will have a look at it next week. A quick test with the SDK simulator 4.0, showed that object associations seem to work fine in the simulator now :) (or at least, they seem to work and no work around is necessary ). I think the workaround code is not necessary any more. |
From: Paul P. <bay...@gm...> - 2010-07-20 05:40:09
|
Yep, thanks! I was also able to get associative references working with the SDK simulator 4.0. I ran into an anomaly where they do NOT work in java_lang_Object.m. After a while, I was able to determine that it works once the imports for java_lang_Class.h & java_lang_String.h are removed. Unfortunately, the former import cannot be removed. One solution is to just make a new category of java_lang_Object in a separate file & use the associative references, etc. there. However, I'd rather get down to the root cause to see why this is happening. I'll dig in further later this week. Thanks! Paul Poley On Sun, Jul 18, 2010 at 5:47 PM, Panayotis Katsaloulis < pan...@pa...> wrote: > > On 17 Ιουλ 2010, at 5:36 μ.μ., Panayotis Katsaloulis wrote: > > > 17 Ιουλ 2010, 11:49 π.μ., ο/η Arno Puder <ar...@pu...> έγραψε: > > > >> > >> I also wanted to say something about the associations. Panayotis has > >> reported that they don't work in the simulator but do work on the actual > >> device. Apparently you've implemented your own solution as a > >> consequence. I would strongly advise against this. For one, it only > >> matters if it works correctly on the device. I've heard many times that > >> you cannot get around testing on the real device because of many subtle > >> differences between the simulator and the device. So, we should optimize > >> for the device; not the simulator. If the simulator version leaks > >> memory, so be it. I'm sure Apple will fix that in the next version of > >> the SDK. > > > > Just a quick note: > > The problem with associations in the simulator was in the previous > version of the SDK. It is possible that with the release of 4.0 this is not > the case any more. Right now I am practically away from my computer but I > will have a look at it next week. > > > A quick test with the SDK simulator 4.0, showed that object associations > seem to work fine in the simulator now :) > (or at least, they seem to work and no work around is necessary ). > I think the workaround code is not necessary any more. > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > |
From: Arno P. <ar...@pu...> - 2010-07-28 18:12:43
|
I just committed your patch. Nice job, Paul! Arno On 7/25/10 1:50 PM, Paul Poley wrote: > I have just submitted my patch for synchronization, wait(), wait(long), > notify() & notifyAll(). > I think this will be a great addition to XMLVM. > > I now know what you were referring to, Arno, about how "the simulator > version leaks memory". The root cause of failed associative references > due to importing java_lang_Class.h & java_lang_String.h was xmlvm.h. > Since the Simulator did not support associated references until > recently, a change was previously made to get around that. That blocked > associated references in the simulator for SDK4. Fortunately, that is > not needed anymore, and you'll see I've commented that out in my patch > (69001). > > To help testing, I've attached a demo project. There's a couple of > scenarios in there. I've tested a lot more than is immediately shown in > the demo. By default, the demo has 2 threads that are notified via > notifyAll() from another thread. > > Also, it will probably help testing if you uncomment out the NSLog > statements in java_lang_Object.m. > Also, after generating the obj-c code, I like to go into my Logger & > change the single println to NSLog instead so it includes a timestamp. > > Thanks! > Paul Poley > > > 2010/7/20 Paul Poley <bay...@gm... <mailto:bay...@gm...>> > > Yep, thanks! I was also able to get associative references working > with the SDK simulator 4.0. > > I ran into an anomaly where they do NOT work in java_lang_Object.m. > After a while, I was able to determine that it works once the > imports for java_lang_Class.h & java_lang_String.h are removed. > Unfortunately, the former import cannot be removed. > > One solution is to just make a new category of java_lang_Object in a > separate file & use the associative references, etc. there. > However, I'd rather get down to the root cause to see why this is > happening. I'll dig in further later this week. > > Thanks! > Paul Poley > > On Sun, Jul 18, 2010 at 5:47 PM, Panayotis Katsaloulis > <pan...@pa... <mailto:pan...@pa...>> wrote: > > > On 17 Ιουλ 2010, at 5:36 μ.μ., Panayotis Katsaloulis wrote: > > > 17 Ιουλ 2010, 11:49 π.μ., ο/η Arno Puder <ar...@pu... > <mailto:ar...@pu...>> έγραψε: > > > >> > >> I also wanted to say something about the associations. > Panayotis has > >> reported that they don't work in the simulator but do work > on the actual > >> device. Apparently you've implemented your own solution as a > >> consequence. I would strongly advise against this. For one, > it only > >> matters if it works correctly on the device. I've heard many > times that > >> you cannot get around testing on the real device because of > many subtle > >> differences between the simulator and the device. So, we > should optimize > >> for the device; not the simulator. If the simulator version > leaks > >> memory, so be it. I'm sure Apple will fix that in the next > version of > >> the SDK. > > > > Just a quick note: > > The problem with associations in the simulator was in the > previous version of the SDK. It is possible that with the > release of 4.0 this is not the case any more. Right now I am > practically away from my computer but I will have a look at it > next week. > > > A quick test with the SDK simulator 4.0, showed that object > associations seem to work fine in the simulator now :) > (or at least, they seem to work and no work around is necessary ). > I think the workaround code is not necessary any more. > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first <http://sprint.com/first> -- > http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > xmlvm-users mailing list > xml...@li... > <mailto:xml...@li...> > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > > > > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |