Closed jjfiv closed 12 years ago
I'm going to write some loosely connected statements to make sure I understand everything correctly. Since I promised to post within the hour, this is incomplete. I'll be editing, but I wanted to get it into the pipeline first (haw haw), since I'm not terribly effective at the superscalar thing (haw haw).
We have a notion of threads inside the VM. This is our Thread.js
Java has its own Thread object, which has certain features. When a user program creates a new Thread, this is done in a variety of ways. Regardless of implementation, the call to start the thread is located in the Runnable interface.
This Java Thread class needs to be intercepted by our machine, much like calls to Class or Object. This will be implemented in a new file called invoke.js
I'm using the term "intercept" to denote the case where the invoke call would defer to the kinds things currently implemented as "hacks." I chose the term because we are intercepting them before they get to the vanilla invoke handler.
We would need to ensure that the following subtasks (not listed in any particular order) are completed:
run
and whether the method implements Runnable
. While Threads can also be created by subclassing Thread
, Thread
also implements Runnable, so we're probably fine just checking for Runnable
.new-instance
. Static fields, as with any class, are shared amongst all Threads. We shouldn't need any special "hardware" for this.state
field to the Thread object, corresponding to the State inner class of Java's Thread. Write corresponding intercepts for valueOf and valuesDo we handle deprecated functions? Testing: Threads can be made in the following ways, so we ought to test each:
Runnable
as a named classRunnable
as an anonymous classThread
as a named classThread
as an anonymous class?
Each of these with each of the overloaded options (or maybe the maximal supersets)?Are we going to want to implement Exceptions first?
So looking back on your original comment, it seems like there are two ways to proceed: do it ad hoc via intercepts (ie the above first pass commentary) or implement a kind of staging area. Do you think we can slip something between dexLoader and starting the VM to encapsulate thread behavior? We could hook it up to executing code by tagging stackframes with the thread responsible for their behavior.
Getting the current "VM Thread" from the current "VM Stackframe" should be easy.
My idea was kind of that we could create a class with a bunch of methods that would have "native" elements rather than "icode" elements, or something.
We can also clean up the invoke, like you described.
I honestly don't think it matters. We're still going to need to collect the hacks in one place -- whether that's in invoke or in some stage of loading the VM, I don't see either one being particularly easier.
So maybe a first pass in invoke
:question: I hate to be that person, but maybe this problem would be best solved via test-driven development? :hammer: :hammer: :hamburger:
Anything thoughts on java.util.Random vs native javascript random?
java.util.Random isn't exactly on my list to implement. Wish-list feature, if we're done Saturday. Same goes for scheduling algorithms, unfortunately.
On 10/29/2012 03:52 PM, etosch wrote:
Anything thoughts on java.util.Random vs native javascript random?
— Reply to this email directly or view it on GitHub https://github.com/jjfiv/dalvik-js/issues/91#issuecomment-9882863.
If by Test-Driven Development, you mean, create a java file and push it through, then absolutely. Doing any significant design without a test case to work toward would be irresponsible.
On 10/29/2012 03:47 PM, etosch wrote:
So maybe a first pass in |invoke|:question: I hate to be that person, but maybe this problem would be best solved via test-driven development? :hammer::hammer::hamburger:
— Reply to this email directly or view it on GitHub https://github.com/jjfiv/dalvik-js/issues/91#issuecomment-9882706.
Okay, so for now we're going to ignore random instructions? throw an error? supply hard-coded instructions? use native javascript random? I guess my vote goes towards saying that we won't support it.
Yeah I don't know if test-driven development is what they call it; I think it's a buzzword I heard somewhere and using my superior powers of reading comprehension I grafted some meaning onto it to serve my needs...
I'm off to reading papers now. Will check back in in a few hours. My goal before the end of the night is to push a comprehensive and incremental tester (the comprehensive part will package all the thread tests as a single file. the incremental part will be the individual tests that test a single feature.)
Barring any issues with power, ping me for an update around 10pm?
I didn't read all of your investigation; I'll look into what kind of randomness you're talking about because we don't seem to be on the same page. There is no "random" instruction in Dalvik, so if we need it for a library call, we can use javascripts, if necessary.
On 10/29/2012 03:59 PM, etosch wrote:
Okay, so for now we're going to ignore random instructions? throw an error? supply hard-coded instructions? use native javascript random? I guess my vote goes towards saying that we won't support it.
Yeah I don't know if test-driven development is what they call it; I think it's a buzzword I heard somewhere and using my superior powers of reading comprehension I grafted some meaning onto it to serve my needs...
I'm off to reading papers now. Will check back in in a few hours. My goal before the end of the night is to push a comprehensive and incremental tester (the comprehensive part will package all the thread tests as a single file. the incremental part will be the individual tests that test a single feature.)
— Reply to this email directly or view it on GitHub https://github.com/jjfiv/dalvik-js/issues/91#issuecomment-9883140.
Ah, I see, random is totally my fault. Let's just come up with examples that avoid randomness for now. Getting something working with Threads is first; getting them scheduled better is after that.
:+1:
Is this closed now that subissues have been created?
Not yet; I need to review the thread and make sure all comments/concerns are covered by the new issues. I'll close after addressing these.
On Wed, Oct 31, 2012 at 12:26 PM, John Foley notifications@github.comwrote:
Is this closed now that subissues have been created?
— Reply to this email directly or view it on GitHubhttps://github.com/jjfiv/dalvik-js/issues/91#issuecomment-9951510.
Emma Tosch Graduate Research Assistant, Computational Intelligence Lab, Hampshire College MS/PhD student, University of Massachusetts, Amherst etosch@cs.umass.edu http://cs.umass.edu/~etosch
A lot of issues have been resolved on Threads; goals are now limited to a better scheduler for Thread.sleep Issue #100
Some reading material on Threads in Java
I was remembering incorrectly;
run()
is on a user subclass ofRunnable
, not ofThread
so we'll need to do that.We'll probably need hooks inside of
new-instance
to manufacture our own "synthetic" Thread objects, and we'll need hooks in invoke to catch all the methods...I think maybe the best way to be doing these things is to have a flag on methods that let us know if the implementation is in javascript, and a function attached to it rather than icode to execute. This would allow our hacks within invoke to be small, and allow us to define objects elsewhere in javascript? Maybe this would just move the hacks to
new-instance
...So this is a design/find subtasks sort of challenge. Let me know if I can help.