mfence on i686 with volatile?

David Holmes - Sun Microsystems David.Holmes at Sun.COM
Wed Nov 18 01:42:49 UTC 2009


Denis,

This is OT for the discuss mailing list so I've moved it to hotspot-dev. 
(discuss-list was bcc'ed).

Regards,
David Holmes

Dennis Byrne said the following on 11/18/09 09:28:
> I am not observing any fences in the output from PrintAssembly.  The
> following java produces the following assembly, regardless of whether
> or not I make v and v2 volatile.
> 
> class HelloWorld extends Thread{
>   public static int v = 0;
>   public static int v2 = 1;
>   public static void main(String[] args){
> 	new HelloWorld().start();
> 	new HelloWorld().start();
>   }
>   public void run() {
>        for(int i = 0; i < 1000000; i++){
> 		v += 333;
> 		v2 += v;
>        }
>        System.out.println(v);
>        System.out.println(v2);
>   }
> }
> 
> 
>   0x02e33d30: mov	%eax,-0x3000(%esp) ;
>   0x02e33d37: push	%ebp               	        ;
>   0x02e33d38: mov	%esp,%ebp          	;
>   0x02e33d3a: sub	$0x28,%esp         	;
>   0x02e33d3d: mov	$0x0,%esi          	;
>   0x02e33d42: jmp	0x02e33d7a         	;
>   0x02e33d47: nop				        ;
>   0x02e33d48: mov	$0x95ba5348,%edx   	;
> 
>   0x02e33d4d: mov	0x1b8(%edx),%ecx   	;
>   0x02e33d53: add	$0x14d,%ecx        	; v += 333
>   0x02e33d59: mov	%ecx,0x1b8(%edx)   	;
>   0x02e33d5f: mov	0x1bc(%edx),%ecx   	;
>   0x02e33d65: mov	0x1b8(%edx),%edi   	;
>   0x02e33d6b: add	%edi,%ecx          	; v2 += v
>   0x02e33d6d: mov	%ecx,0x1bc(%edx)   	;
>   0x02e33d73: inc	%esi               	        ; i++
>                                         	;
>                                         	;
>                                         	; - HelloWorld::run at 31 (line 12)
> 
> 



More information about the discuss mailing list