Debugging and Understanding Newspeak on Squeak

43 views
Skip to first unread message

Jan Sinschek

unread,
Nov 6, 2012, 12:01:04 PM11/6/12
to newspeak...@googlegroups.com
Hi,

I am trying to get a grasp on the compilation and installation procedure in Newspeak, and have been step-debugging the compilation of a class via "compile File" from Newspeak3CompilerAdapter´compileUnit: onwards, trying to learn how Newspeak manages to pretend mixins and virtal classes through Smalltalk entities.

I have used the debugger extensively during this time, and noticed frequent problems of different kinds when step-debugging code that runs fine when not interrupted. I understand that these might in some cases be luxury problems, but wanted to draw attention to three problems I had.

1) As attached, a bug crops up when I walk through
Compiler(Newspeak2SqueakCompilation`Compiler)>>methodNode:
as an initializer (or the primary factory?) is being created. The stack trace shows that LowLevelMethodMirror`LowLevelMethodMirror`byte is uninitialized, although it is initiliazed via ::=. This is not a problem when not debugging, and it did not occur when I tried a different source file. However, getting there via the debugger takes minutes due to its slowness, so you tell me whether it's somewhat valuable to look into.
2) There is a breakdown of the debugger when a metaclass is instantiated as part of ActivationSubject asking for the receiver class.
3) Aggressive garbage collections through the squeak console seem to break a running debugger session.

Through all this, I am really looking for an explanation of how Newspeak classes come about, and I have understood some of it. It would still be helpful to see - maybe to pduti as well at this point (?) how mixins and classes are represented in the runtime.
I assume Smalltalk classes are created to represent (virtual) newspeak classes, and that the bytecodes created by an AST traversal from NS2Squeak's to-bytecode visitor define the actual low-level methods that are found in these classes.
It is also clear to me that the ClassDeclarationBuilder's output is not installed code- that is what installAtomically is for. Still, I wonder at which point a class is "patched up" to its proper enclosing object, and where the dispatch to outer is actually put in.

My goal in this is the (potential) replacement of constructors as mentioned in the "Building Newspeak" thread - for that I must understand where I can get a 'new' primary factory that will potentially return a different object. (As this shows, I am not sure what I need to do- hence my desire to understand how the compiler/the installation works.)

That said, I unfortunately have to leave,´
jan

Ryan Macnak

unread,
Nov 6, 2012, 2:21:49 PM11/6/12
to newspeak...@googlegroups.com
On Tue, Nov 6, 2012 at 12:01 PM, Jan Sinschek <sro...@googlemail.com> wrote:
trying to learn how Newspeak manages to pretend mixins and virtal classes through Smalltalk entities.

As of Oct 2011, Newspeak classes and mixins are no longer represented as Squeak classes. Newspeak classes and mixins are represented as instances of the classes in Kernel. Reading the comments of the classes nested in Kernel and exploring some things like platform class and platform class mixin in the inspector would be good places to start. In the past I have found drawing a complete small example with each mixin/class/instance and all of the classof, mixinof, instanceof references between them to be helpful.
  
3) Aggressive garbage collections through the squeak console seem to break a running debugger session.

'Garbage Collect Aggressively' calls NsToolSet releaseMemory, which involves releasing any processes held by the debugger. The UI should be updated to reflect this.
 
Through all this, I am really looking for an explanation of how Newspeak classes come about, and I have understood some of it.

Newspeak classes are born during InstanceMixin>>apply:[withName:] in InstanceMixin>>invokeWithSuperclass:withName:.
 
It would still be helpful to see - maybe to pduti as well at this point (?) how mixins and classes are represented in the runtime. I assume Smalltalk classes are created to represent (virtual) newspeak classes,

No, Newspeak classes are represented by Kernel`Class and Kernel`Metaclass rather than Smalltalk at: #Class and Smalltalk at: #Metaclass. (The layout of these classes matches the Squeak ones for all the fields that the VM cares about.)
 
and that the bytecodes created by an AST traversal from NS2Squeak's to-bytecode visitor define the actual low-level methods that are found in these classes.

Yes.
 
It is also clear to me that the ClassDeclarationBuilder's output is not installed code- that is what installAtomically is for. Still, I wonder at which point a class is "patched up" to its proper enclosing object,

For a new class declaration, atomic installer does create any classes. The top-level class comes into existence afterward, when the IDE applies the top-level mixin to Object.

A mixin application can get its enclosing object in three ways:
1) explicit mixin applications in Class>>mixinApply:
2) nested classes in their synthetic accessors (for an example, inspect time yourself class methodDictionary at: #Time)
3) retaining the default of nil when created by InstanceMixin>>apply: (this is a bug)

and where the dispatch to outer is actually put in.

The pushImplicitReceiver or pushOuterReceiver bytecodes.

Jan Sinschek

unread,
Nov 7, 2012, 5:34:12 AM11/7/12
to newspeak...@googlegroups.com
On 06.11.2012 20:21, Ryan Macnak wrote:
> On Tue, Nov 6, 2012 at 12:01 PM, Jan Sinschek <sro...@googlemail.com
> <mailto:sro...@googlemail.com>> wrote:
>
> trying to learn how Newspeak manages to pretend mixins and virtal
> classes through Smalltalk entities.
>
>
> As of Oct 2011, Newspeak classes and mixins are no longer represented as
> Squeak classes. Newspeak classes and mixins are represented as instances
> of the classes in Kernel.

Ah, that's how it all connects... Thank you! So, one thing I still
wonder about is that in compileUnit: the last lines are:

mixinMirror:: builder install.
klass:: mixinMirror reflectee apply: NSObject withName: mixinMirror
simpleName.
(*klass :A Newspeak class*)
Smalltalk at: klass name put: klass.
klass category: mixinMirror reflectee definingClass category.
blackMarket SystemOrganization classify: klass name under: klass
category.

Does Smalltalk really need the klass (a Kernel`Class referencing its
MetaClass) in its globals-dictionary? Is that obsolete code?
compileUnit: is apparently only reached when I do 'compile file' through
the IDE (and through some seemingly deprecated toNS3-converter).

> 3) Aggressive garbage collections through the squeak console seem to
> break a running debugger session.
>
>
> 'Garbage Collect Aggressively' calls NsToolSet releaseMemory, which
> involves releasing any processes held by the debugger. The UI should be
> updated to reflect this.
should I file a bug?



Thank you again,
jan

Ryan Macnak

unread,
Nov 7, 2012, 9:54:34 PM11/7/12
to newspeak...@googlegroups.com
On Wed, Nov 7, 2012 at 5:34 AM, Jan Sinschek <sro...@googlemail.com> wrote:
Does Smalltalk really need the klass (a Kernel`Class referencing its MetaClass) in its globals-dictionary? Is that obsolete code? compileUnit: is apparently only reached when I do 'compile file' through the IDE (and through some seemingly deprecated toNS3-converter).

Some code written in Squeak needs to access Newspeak classes, for example NativeSession and BlackMarket. Consider this an implementation artifact. Someday the IDE namespace will be separate. (And some later day there won't be any Squeak code.)

    3) Aggressive garbage collections through the squeak console seem to
    break a running debugger session.


'Garbage Collect Aggressively' calls NsToolSet releaseMemory, which
involves releasing any processes held by the debugger. The UI should be
updated to reflect this.
should I file a bug?
 
Yes. Either the UI should switch to the 'thread is terminated' view or the processes in debuggers in a live windows shouldn't be released. Vassili?
Reply all
Reply to author
Forward
0 new messages