JavaNativeMethod.st
branchcvs_MAIN
changeset 3360 1a8899091305
parent 3325 d9297d724fa0
child 3386 ddcff50a1fdc
--- a/JavaNativeMethod.st	Fri Feb 14 14:27:26 2014 +0100
+++ b/JavaNativeMethod.st	Wed Jan 28 03:12:08 2015 +0100
@@ -1,9 +1,9 @@
 "
- COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 1996-2015 by Claus Gittinger
 
  New code and modifications done at SWING Research Group [1]:
 
- COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+ COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
                             SWING Research Group, Czech Technical University in Prague
 
  This software is furnished under a license and may be used
@@ -20,6 +20,8 @@
 "
 "{ Package: 'stx:libjava' }"
 
+"{ NameSpace: Smalltalk }"
+
 JavaMethodWithHandler variableSubclass:#JavaNativeMethod
 	instanceVariableNames:'nativeImplementation nCalls'
 	classVariableNames:'CacheNativeImplementation Verbose TrampolineSelectors'
@@ -29,16 +31,13 @@
 
 !JavaNativeMethod class methodsFor:'documentation'!
 
-alize
-!
-
 copyright
 "
- COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 1996-2015 by Claus Gittinger
 
  New code and modifications done at SWING Research Group [1]:
 
- COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+ COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
                             SWING Research Group, Czech Technical University in Prague
 
  This software is furnished under a license and may be used
@@ -215,59 +214,69 @@
 
 !JavaNativeMethod methodsFor:'private'!
 
-compileNativeImplementation: sel dispatchingTo: oldSel
+compileNativeImplementation:sel dispatchingTo:oldSel 
+    | src  arg  converted  header |
 
-    | src arg converted header |
-    src := (JavaVM class compiledMethodAt: oldSel) source.
+    src := (JavaVM class compiledMethodAt:oldSel) source.
     src := src asStringCollection.
-    (src first includesString: 'aJavaContext') ifTrue:[
+    (src first includesString:'aJavaContext') ifTrue:[
         arg := 'aJavaContext'
     ] ifFalse:[
-        (src first includesString: 'nativeContext') ifTrue:[
+        (src first includesString:'nativeContext') ifTrue:[
             arg := 'nativeContext'
         ]
     ].
-    arg ifNotNil:[
-        src removeFirst asString.
-        converted := true.
-    ] ifNil:[
+    arg isNil ifTrue:[
         arg := 'nativeContext'.
         src := '    self breakPoint: #jv info: ''Convert it to new-style natives''.
 
-                ^ self ', oldSel, ' nativeContext'.
-        converted := false.            
-    ]. 
-
-    header := String streamContents:[:s|
-        sel numArgs == 2 ifTrue:[
-            s nextPutAll: sel; space; nextPutAll: 'this  '.
-        ] ifFalse:[
-            | kw |
+                ^ self ' 
+                , oldSel , ' nativeContext'.
+        converted := false.
+    ] ifFalse:[
+        src removeFirst asString.
+        converted := true.
+    ].
+    header := String 
+            streamContents:[:s | 
+                sel numArgs == 2 ifTrue:[
+                    s
+                        nextPutAll:sel;
+                        space;
+                        nextPutAll:'this  '.
+                ] ifFalse:[
+                    | kw |
 
-            kw := sel keywords.            
-            s nextPutAll: kw first.
-            s nextPutAll: ' this '.
-            2 to: kw size - 1 do:[:i|
-                sel nextPutAll: (kw at: i); space; nextPut:$a; nextPutAll: i printString; space.
-            ].            
-        ]
-    ].
-
-    (JavaVM class 
-        compile:
-            (self nativeMethodTemplate bindWith:header with: arg with: src asString)
-        classified:         
-            'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$. ))
-        package: JavaVM package.
-
+                    kw := sel keywords.
+                    s nextPutAll:kw first.
+                    s nextPutAll:' this '.
+                    2 to:kw size - 1 do:[:i | 
+                        sel
+                            nextPutAll:(kw at:i);
+                            space;
+                            nextPut:$a;
+                            nextPutAll:i printString;
+                            space.
+                    ].
+                ]
+            ].
+    (JavaVM class compile:(self nativeMethodTemplate 
+                bindWith:header
+                with:arg
+                with:src asString)
+        classified:'native - ' 
+                , ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$.)) 
+            package:JavaVM package.
     converted ifTrue:[
-        (JavaVM class compiledMethodAt: oldSel) category: 'native - old-style (converted)'
+        (JavaVM class compiledMethodAt:oldSel) 
+            category:'native - old-style (converted)'
     ] ifFalse:[
-       (JavaVM class compiledMethodAt: oldSel) category:  'native - old-style (FAILED to convert)'
+        (JavaVM class compiledMethodAt:oldSel) 
+            category:'native - old-style (FAILED to convert)'
     ]
 
     "Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-01-2013 / 23:29:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 04-08-2014 / 15:51:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 compileNativeImplementationStub: sel
@@ -288,17 +297,18 @@
 
     ].
 
-    (JavaVM natives class 
-        compile:
-            (self nativeMethodTemplate bindWith:header with: 'nativeContext' with:('^ JavaVM unimplementedNativeMethodSignal raise'))
-        classified:         
-            'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$.))
-        package: JavaVM package.
-
+    Class updateChangeFileQuerySignal answer: false do:[
+        (JavaVM natives class 
+            compile:
+                (self nativeMethodTemplate bindWith:header with: 'nativeContext' with:('^ JavaVM unimplementedNativeMethodSignal raise'))
+            classified:         
+                'native - ', ((javaClass javaPackage upTo:$$) replaceAll:$/ with:$.))
+            package: JavaVM package.
+    ].
     self assert: (JavaVM natives respondsTo: sel).
 
     "Created: / 01-05-2011 / 00:08:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 04-03-2013 / 17:31:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-01-2015 / 09:14:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 nativeMethodTemplate
@@ -381,7 +391,7 @@
         "14" '_:_:_:_:_:_:_:_:_:_:_:_:_:_:'
     ) at: numArgs + 1.
 
-    newStyleSel := ('_' , ((javaClass name copyReplaceAll:$/ with:$_) replaceAll:$$ with:$_), '_' , nm , ':' , args) asSymbol.    
+    newStyleSel := ('_' , ((javaClass binaryName copyReplaceAll:$/ with:$_) replaceAll:$$ with:$_), '_' , nm , ':' , args) asSymbol.    
     (JavaVM natives class canUnderstand: newStyleSel) ifTrue:[
         "Good, a JavaVM understands new style native selectors"
         "No checke whether the descriptor is the same."
@@ -406,7 +416,7 @@
     ^newStyleSel
 
     "Created: / 19-01-2013 / 22:11:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 06-05-2013 / 22:03:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-10-2013 / 01:43:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaNativeMethod methodsFor:'private-compiler interface'!
@@ -495,10 +505,7 @@
 
 %{
     /* Now, try to bind to C-optimized native method */
-    /* Not supported by eXept librun */
-#if 0
     __jbindnative(self);
-#endif
 %}.
 
 
@@ -506,6 +513,27 @@
     "Modified: / 10-03-2013 / 01:39:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!JavaNativeMethod methodsFor:'queries'!
+
+lineNumberForPC0: pc
+    | src name lineNumber |
+
+    src := javaClass source.
+    src notNil ifTrue:[    
+        name := self name.
+        src asStringCollection withIndexDo:[:l :lno|
+            ((l includesString: 'native') and:[l includesString: name]) ifTrue:[
+                lineNumber := lno.
+                ^ lineNumber
+            ].
+        ]. 
+    ].
+    lineNumber := 1.
+    ^ lineNumber
+
+    "Created: / 08-08-2014 / 07:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaNativeMethod methodsFor:'vm support'!
 
 nativeMethodInvokation
@@ -568,11 +596,11 @@
 !JavaNativeMethod class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libjava/JavaNativeMethod.st,v 1.17 2013-09-06 00:41:24 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libjava/JavaNativeMethod.st,v 1.18 2015-01-28 02:10:50 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libjava/JavaNativeMethod.st,v 1.17 2013-09-06 00:41:24 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libjava/JavaNativeMethod.st,v 1.18 2015-01-28 02:10:50 vrany Exp $'
 !
 
 version_SVN