PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/tutorial/external/Java/example6.e

http://github.com/tybor/Liberty
Specman e | 102 lines | 62 code | 15 blank | 25 comment | 0 complexity | d34133632d7905f5b0e4700d594ed157 MD5 | raw file
  1class EXAMPLE6
  2	-- Compilation:
  3	--    compile_to_jvm example6
  4	-- Execution:
  5	--    java example6
  6	-- This example demonstrates how to set Java field attributes of Eiffel
  7	-- class attributes, how to declare a method synchronized, and how to
  8	-- construct a synchronized block.
  9
 10creation {ANY}
 11	make
 12
 13feature {ANY}
 14	make is
 15		do
 16			field_attributes
 17			synchronized_test
 18			monitor_test
 19		end
 20
 21feature {ANY}
 22	field_attributes is
 23			-- have to look at dump of classfile to verify that
 24			-- var1 is public
 25			-- var2 is public and transient
 26			-- var3 is public and volatile
 27			-- var4 is public and transient and volatile
 28			-- Note: The field_is_transient and field_is_volatile procedure calls
 29			-- must be in a routine in the Eiffel class that will not be optimized
 30			-- out at compile time. The best place to put them is in a creation
 31			-- procedure that you know will be called at runtime.
 32		do
 33			field_is_transient("var2")
 34			field_is_volatile("var3")
 35			field_is_transient("var4")
 36			field_is_volatile("var4")
 37			var1 := 1
 38			var2 := 1
 39			var3 := 1
 40			var4 := 1
 41		end
 42
 43feature {ANY}
 44	var1: INTEGER
 45
 46	var2: INTEGER
 47
 48	var3: INTEGER
 49
 50	var4: INTEGER
 51
 52feature {ANY}
 53	synchronized_test is
 54			-- have to look at dump of classfile to verify that this method is synchronized
 55			-- Note: The routine_is_synchronized procedure call must be within the Eiffel routine
 56			-- to be declared synchronized. It generates no code.
 57		local
 58			i: INTEGER
 59		do
 60			routine_is_synchronized
 61			i := 1
 62		end
 63
 64	monitor_test is
 65			-- have to look at dump of classfile to verify that this Eifel routine has
 66			-- monitorenter and monitorexit calls ( in Java, this would be a
 67			-- synchronized block )
 68			-- the user is responsible for ensuring that each monitorenter is matched
 69			-- by a correspondng monitorexit on the same object
 70		local
 71			i: INTEGER
 72		do
 73			i := 0 -- start of synchronized block
 74			monitor_enter(Current.to_pointer)
 75			i := 1
 76			monitor_exit(Current.to_pointer)
 77			-- end of synchronized block
 78			i := 2
 79		end
 80
 81feature {ANY} -- externals
 82	field_is_transient (s: STRING) is
 83		external "Java transient"
 84		end
 85
 86	field_is_volatile (s: STRING) is
 87		external "Java volatile"
 88		end
 89
 90	routine_is_synchronized is
 91		external "Java synchronized"
 92		end
 93
 94	monitor_enter (p: POINTER) is
 95		external "Java monitorenter"
 96		end
 97
 98	monitor_exit (p: POINTER) is
 99		external "Java monitorexit"
100		end
101
102end -- class EXAMPLE6