Added support for "special cells section"
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sat, 26 Dec 2015 14:41:41 +0100
changeset 5 7b9132bf8295
parent 4 f2d0d2859193
child 6 ff36d8318020
Added support for "special cells section" This section provide access to a special memory cells used by Smalltalk/X VM to maintain code LRU cache. Make sure CompiledCodeObject retains the CompiledCode so the underlaying VM structure is not GCed while there's a reference to smalltalk CompiledCodeObject.
CompiledCodeObject.st
CompiledCodeObjectSection.st
CompiledCodeObjectSectionType.st
CompiledCodeObjectTests.st
--- a/CompiledCodeObject.st	Wed Dec 16 00:03:56 2015 +0000
+++ b/CompiledCodeObject.st	Sat Dec 26 14:41:41 2015 +0100
@@ -24,7 +24,7 @@
 "{ NameSpace: Smalltalk }"
 
 ExternalAddress subclass:#CompiledCodeObject
-	instanceVariableNames:'sections'
+	instanceVariableNames:'compiledCode sections'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'System-Compiler-Interface'
@@ -75,35 +75,51 @@
      object for it. If the method or block is not dynamically compiled,
      throw an exception"
 
-     | instance |
+    | instance |
 
-     instance := self new.
+    instance := self new.
 %{
     stx_compiled_code_object code_object;
     code_object = stxCompiledCodeObjectForCompiledCode(aCompiledCode);
-    if (code_object != NULL) {
+    if (code_object == NULL) {
+        instance = nil;
+    } else {
         __externalAddressVal(instance) = code_object;
-        RETURN ( instance );
     }
 %}.
-    self error: 'Not a dynamic code or not yet compiled'
+    instance isNil ifTrue:[ 
+        self error: 'No code object associated with given method. Method not yet compiled?'
+    ].
+    instance setCompiledCode: aCompiledCode.
+    ^ instance.
 
     "Created: / 07-12-2015 / 10:58:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-01-2016 / 09:39:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompiledCodeObject methodsFor:'accessing'!
 
-methodOrBlock
+compiledCode
     "Return method or block associated with this code object."
+
+    | compiledCodeFromObject |
+
+    compiledCodeFromObject := compiledCode.
 %{
-    stx_compiled_code_object code_object = (stx_compiled_code_object)(__externalAddressVal(self));
-    if (code_object != NULL) {
-        RETURN ( stxCompiledCodeObjectGetCompiledCode(code_object) );
+    if (__ExecutableCodeInstPtr(__INST(compiledCode))->ex_code != NULL) {
+        if ( (INT)(__ExecutableCodeInstPtr(__INST(compiledCode))->ex_flags) & __MASKSMALLINT(F_DYNAMIC)  ) {
+            stx_compiled_code_object code_object = (stx_compiled_code_object)(__externalAddressVal(self));
+            if (code_object != NULL) {
+                compiledCodeFromObject = stxCompiledCodeObjectGetCompiledCode(code_object);
+            }
+        }
     }
 %}.
-    ^ 0
+    self assert: compiledCode == compiledCodeFromObject
+         description: 'compiled code mismatch'.
+    ^ compiledCode.
 
-    "Created: / 07-12-2015 / 11:51:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 11-01-2016 / 09:31:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 sections
@@ -118,6 +134,14 @@
     "Created: / 07-12-2015 / 17:09:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CompiledCodeObject methodsFor:'initialization'!
+
+setCompiledCode: aCompiledCode
+    compiledCode := aCompiledCode
+
+    "Created: / 11-01-2016 / 09:50:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !CompiledCodeObject methodsFor:'inspecting'!
 
 inspector2TabText
--- a/CompiledCodeObjectSection.st	Wed Dec 16 00:03:56 2015 +0000
+++ b/CompiledCodeObjectSection.st	Sat Dec 26 14:41:41 2015 +0100
@@ -139,6 +139,12 @@
     ^ type == SectionTypeText
 
     "Created: / 11-12-2015 / 10:35:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+
+isSCLsSection
+    ^ type == SectionTypeSCLs
+
+    "Created: / 11-12-2015 / 10:35:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+
 ! !
 
 !CompiledCodeObjectSection class methodsFor:'documentation'!
--- a/CompiledCodeObjectSectionType.st	Wed Dec 16 00:03:56 2015 +0000
+++ b/CompiledCodeObjectSectionType.st	Sat Dec 26 14:41:41 2015 +0100
@@ -15,7 +15,7 @@
 
 SharedPool subclass:#CompiledCodeObjectSectionType
 	instanceVariableNames:''
-	classVariableNames:'SectionTypeData SectionTypeText SectionTypeLits SectionTypeILCs'
+	classVariableNames:'SectionTypeData SectionTypeText SectionTypeLits SectionTypeILCs SectionTypeSCLs'
 	poolDictionaries:''
 	category:'System-Compiler-Interface'
 !
@@ -46,7 +46,8 @@
     SectionTypeData := 0.
     SectionTypeText := 1.
     SectionTypeLits := 2.
-    SectionTypeILCs := 3.
+    SectionTypeILCs := 4.
+    SectionTypeSCLs := 5.
 
     "Modified: / 07-12-2015 / 21:43:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
--- a/CompiledCodeObjectTests.st	Wed Dec 16 00:03:56 2015 +0000
+++ b/CompiledCodeObjectTests.st	Sat Dec 26 14:41:41 2015 +0100
@@ -73,21 +73,23 @@
     | object |
     self ensureCompiled: #methodWithConstant.
     object := (self class >> #methodWithConstant) codeObject.
-    self assert: object methodOrBlock == (self class >> #methodWithConstant).
-    self assert: object sections size == 1. "/ No literals no ILC's
+    self assert: object compiledCode == (self class >> #methodWithConstant).
+    self assert: object sections size == 2. "/ No literals no ILC's, only code and special cells
     self assert: object sections first name = '.text'.
     self assert: object sections first type = SectionTypeText.
+    self assert: object sections second name = '.stx.codeobj.specialcells'.
+    self assert: object sections second type = SectionTypeSCLs.
 
 
     self ensureCompiled: #methodWithLiteral.
     object := (self class >> #methodWithLiteral) codeObject.
-    self assert: object sections size == 2. "/ No ILC's but literals
+    self assert: object sections size == 3. "/ No ILC's but literals, code and special cells
 
     self ensureCompiled: #methodWithSend.
-    self assert: object sections size == 2. "/ No literals but ILC
+    self assert: object sections size == 3. "/ No literals but ILC, code and special cells
 
     "Created: / 06-12-2015 / 00:15:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 11-12-2015 / 10:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 11-01-2016 / 09:54:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompiledCodeObjectTests methodsFor:'utilities'!