Re: [Sablevm-developer] locks
Brought to you by:
egagnon
From: Etienne M. G. <eg...@j-...> - 2001-01-12 16:21:21
|
Hi John, I am currently working on locks, and many other things. I am planning for a release in late January. This is a hard deadline as I also have to get some numbers for an accepted JVM'01 paper (http: http://www.usenix.org/events/jvm01/). I had to make many changes within SableVM to implement the paper's popositions. The two word object header will contain many things beyond the thin lock. Also, I was planning to use a single inlined function for the compare-and-swap operation (your code uses more than a single line of inlined asm). If you can wait a couple of weeks, you should get something worth working with. Etienne John Leuner wrote: > > > John Leuner wrote: > > > Have you implemented object locks in SableVM yet? I have had a quick look > > > at the source and didn't find anything there. > > > > Not yet. I have spent too much time writing about SableVM (tech report > > & Ph.D. proposal & presentation slides), and participating to seminars. > > Before I go forward with it, I want to get single threading in a much > > better state. I think that getting exceptions to work, and cleaning the > > memory management code has higher priority. > > > > Do you want to help with implementing locks? I can give you a few > > pointers (in addition to my tech report). > > I'ld like to make a lock implementation for my JVM (kissme), but of course > it should be easy to use in SableVM too. > > So far I have written code to do the atomic test and set: > > (pstObject is the handle to the object we want to lock) > { > //we must do an atomic test and set > int before; > int temp_word; > > //set high bit to 1 > //set bit 23 to 1 > temp_word = 0x80800001; > //set the bits 8-21 to the thread identifier > temp_word |= ( (pthread_self() << 8) & 0x007fff00); > > eprintf("Before lock it is %x and temp_word is %x\n", > ODEREF(pstObject)->lock_word, temp_word); > before = ODEREF(pstObject)->lock_word; > > if(before == 0) //object is unlocked > { > //set eax to 0 > //compare ecx to eax, if they are the same, then copy temp_word > to ecx > __asm__ __volatile__ ( > "movl $0x0, %%eax ; \n" > "movl %1, %%ecx ; \n" > " cmpxchg %%ecx,%0 ; \n" > : "=r" (ODEREF(pstObject)->lock_word) > : "r" (temp_word) , > "0" (ODEREF(pstObject)->lock_word) > : "ax","cx" > ); > } > else > { > if( (ODEREF(pstObject)->lock_word & 0x007fff00) == ( > (pthread_self() << 8) & 0x007fff00)) > { > //we own the lock > //so we just increment the count > temp_word = before + 1; > __asm__ __volatile__ ( > "movl %3, %%eax ; \n" > "movl %1, %%ecx ; \n" > " cmpxchg %%ecx,%0 ; \n" > : "=r" (ODEREF(pstObject)->lock_word) > : "r" (temp_word) , > "0" (ODEREF(pstObject)->lock_word) , "r" (before) > : "ax","cx" > ); > //again we must check if we succeeded > if(temp_word == ODEREF(pstObject)->lock_word) > { > eprintf("Succeeded in doing inc atomic lock\n"); > } > else > { > eprintf("Tried to do incremental lock but failed %x\n", > ODEREF(pstObject)->lock_word); > assert( 4 == 0); > } > } > else //we aren't the owner > { > eprintf("we don't own this lock!!!!\n"); > } > } > > //check if we succeeded > if(temp_word == ODEREF(pstObject)->lock_word) > { > eprintf("Succeeded in doing atomic lock %x\n", > ODEREF(pstObject)->lock_word); > } > else > { > eprintf("Failed in doing atomic lock it is %x and temp_word is %x\n", > ODEREF(pstObject)->lock_word, temp_word)\; > //this means either we, or someone else, owns the lock > > assert( 2 == 3); > } > > I'm reading the report and I'm not sure how a thin lock is inflated to a > fat lock. This is what I have in mind for the contention case: > > if lock is owned by another thread > get owning thread identifier > get thread structure for owning thread > acquire lock for owning thread > set contention bit in thread structure > if lock is still thin and owned by that thread > add tuple to owning threads wait list > sleep (on what?) > else > restore contention bit > release lock for owning thread > repeat this > end > > So does a lock get inflated only during an unlock operation? When it is > inflated, do we use the high bit to distinguish between a thin and fat > lock? Is the fat lock just a pthread_mutex_t on linux? Do we use the lock > word for this? > > John Leuner > > _______________________________________________ > Sablevm-developer mailing list > Sab...@li... > http://lists.sourceforge.net/lists/listinfo/sablevm-developer -- ---------------------------------------------------------------------- Etienne M. Gagnon, M.Sc. e-mail: eg...@j-... Author of SableCC: http://www.sablecc.org/ and SableVM: http://www.sablevm.org/ |