--- a/src/JavaObject.st Tue Aug 28 16:09:58 2012 +0000
+++ b/src/JavaObject.st Mon Sep 03 14:57:38 2012 +0000
@@ -21,7 +21,7 @@
"{ Package: 'stx:libjava' }"
Object subclass:#JavaObject
- instanceVariableNames:''
+ instanceVariableNames:'_lockWord_'
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Classes'
@@ -51,6 +51,32 @@
as of 1.9.2010
"
+!
+
+documentation
+"
+ 'Proto' class for all Java classes: java.lang.Object inherits
+ from JavaObject class. Methods provided here are provides a 'glue'
+ code necessary to integrate Java objects into Smalltalk world.
+
+ The 'lock' instance variable here is to support Java monitors.
+ It contains either smalltinteger with lockword or a reference to
+ full JavaMonitor.
+
+ [author:]
+ Claus Gittinger
+ Jan Vrany <jan.vrany@fit.cvut.cz>
+
+ [instance variables:]
+ _lockWord_ <SmallInteger|JavaMonitor> either thin-locing lock word
+ or fat-lock (JavaMonitor). The funny name
+ here is to prevent name clashes
+
+ [class variables:]
+
+ [see also:]
+
+"
! !
!JavaObject class methodsFor:'misc'!
@@ -125,6 +151,50 @@
"Modified: 8.8.1997 / 12:07:29 / cg"
! !
+!JavaObject methodsFor:'accessing-Java'!
+
+getJavaLockWord
+ "Returns a Java lock word for given object. The returned
+ value is
+ - either SmallInteger that encodes the thinlock
+ - or a fat lock, instance of JavaMonitor
+ "
+
+ "/For nonJava objects, always return fatlock
+
+ ^_lockWord_
+
+ "Created: / 26-08-2012 / 14:03:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+getJavaMonitor
+ "Returns fat JavaMonitor associated with the receiver"
+
+ "/ For Java objects, check if there is allready a thinlock,
+ "/ inflate it and return the fatlock
+
+ _lockWord_ class == SmallInteger ifTrue:[
+ _lockWord_ := JavaVM inflateLockFor: self lockword: _lockWord_.
+ ].
+ ^_lockWord_
+
+ "Created: / 26-08-2012 / 18:35:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+setJavaLockWord: lockWordOrJavaMonitor
+ "Sets a Java lock word for receiver to lockWordOrJavaMonitor.
+ The lockWordOrJavaMonitor must be:
+ - either SmallInteger that encodes the thinlock
+ - or a fat lock, instance of JavaMonitor
+ "
+
+ "/for non-Java objects, store fat lock in LockTable in JavaVM
+
+ ^_lockWord_ := lockWordOrJavaMonitor
+
+ "Created: / 26-08-2012 / 14:07:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!JavaObject methodsFor:'exception handling support'!
catchInDebugger
@@ -410,3 +480,4 @@
version_SVN
^ '$Id$'
! !
+