Character allInstances size=0 for 5.3 latest

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Character allInstances size=0 for 5.3 latest

vaidasd
Hello,
Character allInstances size=0. Why?
regards,
Vaidotas

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

David T. Lewis
On Fri, Feb 28, 2020 at 08:56:46PM +0200, Vaidotas Did??balis wrote:
> Hello,
> Character allInstances size=0. Why?
> regards,
> Vaidotas

Hi Vaidotas,

If you are accustomed to Character as represented in earlier Squeak
(or other Smalltalk) versions, then this result will be surprising.

The reason is that the internal representation of Character has
changed in recent versions of Squeak. We now use an object memory
design (called "Spur") developed by Eliot Miranda that enables a
number of improvements and optimizations.

One important optimization is that instances of Character can now
be represented as "immediate" objects, in which the data for an
instance of a class is actually hidden directly in the "object
pointer" that refers to the instance. That instance is in every
way a real object, but is optimized in such a way that the information
(in this case the character value) is encoded directly ("immediately")
inside the object pointer that specifies the instance.

This optimization allows certain simple objects to be encoded very
efficiently. And it also has the somewhat surprising side effect
of making it appear that there are no "real" instances of the class
when you use #allInstances to scan the object memory looking for
instances of the class.

In earlier versions of Squeak, only class SmallInteger was able
to benefit from this optimization. So in older versions, you will
see this for the optimized SmallInteger:

  SmallInteger allInstances size ==> 0

But for Character, which did not benefit from an internal representation
as an "immediate" class, you might see something like this:

  Character allInstances size ==> 257

Since that time, Character has now been updated to be an immediate
class, and it now behaves much like SmallInteger. Thus on modern Squeak
you will now have:

  Character allInstances size ==> 0

Spur enabled another similar optimization for floating point objects.
On older Squeak versions, you will see that all instances of Float
are ordinary non-immediate objects. So you might see something like
this in an older image:

  Float allInstances size ==> 8362

But on newer Squeak images with the Spur object format, most floating
point objects can now be optimized with an immediate representation.
It depends on the actual numeric values involved, but most Float
objects can be represented by class SmallFloat64, which is an optimized
"immediate" representation that (like SmallInteger) appears to have
no instances when you scan the objects memory:

  SmallFloat64 allInstances size ==> 0

However, some floating point values cannot be packed inside an object
pointer, and these need to be represented by "normal" objects. This
is done with class BoxedFloat64, so your image might show a number
of instances of these non-immediate objects:

  BoxedFloat64 allInstances size ==> 34

Modern Squeak images on Spur still have a class called Float. But
all of the actual instances of Float are represented by two concrete
subclasses. Floating point values that can be packed into an object
pointer are now instances of SmallFloat64, and values that cannot
fit into that optimized format are represented by the "normal"
class BoxedFloat64.

And of course the original class Float is now abstract, so it has
no instances at all:

  Float allInstances size ==> 0

Dave.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

K K Subbu
In reply to this post by vaidasd
On 29/02/20 12:26 AM, Vaidotas Didžbalis wrote:
> Hello,
> Character allInstances size=0. Why?

Good observation!

allInstances gives a list of objects of the given class stored in Object
Memory. Character and SmallInteger are immediate values (type 7), stored
directly in an oop, so they have no instances in Object Memory. You get
other such types with:

Class allSubInstances select: [:c | c instSpec = 7]
   an OrderedCollection(SmallInteger SmallFloat64 Character)

See the comment of Behavior>>instSpec for other instance types.

HTH .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

vaidasd
David and Subbu,
Thank you for your explanations, but ... but we have characters in the image. Having a characters in the image means that Character has instances. If alInstances method cannot report about them, it shall fire exception perhaps, or, name allInstances must be changed to something else, isn't it?
regards,
Vaidotas



On Sat, Feb 29, 2020 at 10:33 AM K K Subbu <[hidden email]> wrote:
On 29/02/20 12:26 AM, Vaidotas Didžbalis wrote:
> Hello,
> Character allInstances size=0. Why?

Good observation!

allInstances gives a list of objects of the given class stored in Object
Memory. Character and SmallInteger are immediate values (type 7), stored
directly in an oop, so they have no instances in Object Memory. You get
other such types with:

Class allSubInstances select: [:c | c instSpec = 7]
   an OrderedCollection(SmallInteger SmallFloat64 Character)

See the comment of Behavior>>instSpec for other instance types.

HTH .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

David T. Lewis
Hi Vaidotas,

all of the things that you suggest are possible, and I would encourage
to you experiment and see what makes sense to you. But I would caution
agaist changing well-known method names unnecessarily, sometimes it is
better to just improve the method comment to reduce surprises.

I don't know your level of experience, but a VM primitive that finds
all (immediate) instances of Character would be an interesting exercise
if you have an interest in that area. To be clear, it's not something
that I would want to spend time on myself, but I'm happy to help you
learn how to do it yourself if you have an interest.

Dave

On Sat, Feb 29, 2020 at 10:11:38PM +0200, Vaidotas Did??balis wrote:

> David and Subbu,
> Thank you for your explanations, but ... but we have characters in the
> image. Having a characters in the image means that Character has instances.
> If alInstances method cannot report about them, it shall fire exception
> perhaps, or, name allInstances must be changed to something else, isn't it?
> regards,
> Vaidotas
>
>
>
> On Sat, Feb 29, 2020 at 10:33 AM K K Subbu <[hidden email]> wrote:
>
> > On 29/02/20 12:26 AM, Vaidotas Did??balis wrote:
> > > Hello,
> > > Character allInstances size=0. Why?
> >
> > Good observation!
> >
> > allInstances gives a list of objects of the given class stored in Object
> > Memory. Character and SmallInteger are immediate values (type 7), stored
> > directly in an oop, so they have no instances in Object Memory. You get
> > other such types with:
> >
> > Class allSubInstances select: [:c | c instSpec = 7]
> >    an OrderedCollection(SmallInteger SmallFloat64 Character)
> >
> > See the comment of Behavior>>instSpec for other instance types.
> >
> > HTH .. Subbu
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://lists.squeakfoundation.org/mailman/listinfo/beginners
> >
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

K K Subbu
In reply to this post by vaidasd
On 01/03/20 1:41 AM, Vaidotas Didžbalis wrote:
> Thank you for your explanations, but ... but we have characters in the
> image. Having a characters in the image means that Character has
> instances. If alInstances method cannot report about them, it shall fire
> exception perhaps, or, name allInstances must be changed to something
> else, isn't it?

Instance has two meanings.

* the first one is as you explain it. This is usually the meaning
intended in all textbooks and applies to the overall object model (e.g.
$a isKindOf: Object is true).

* The second one is an object allocated in memory and is the one of most
interest in practice. Such objects need memory allocation, reference
counting and garbage collection services. The method allInstances uses
the word instances in the latter sense. Immediate objects don't need
these services, so they are not considered. (e.g. $a class
isImmediateClass is true).

This is like calling 45, 045 or 0045 as two digit numbers because
leading zeros are not significant in practice.

Could you explain the context behind your question?

Regards .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

vaidasd
hello Subbu,
Up until now I used v4.4 version image. I thought that my Smalltalk image was broken after it reported that character has zero instances, -- no, I don't need a solution here, it is the concern of having a system which is less coherent than it was (v4.4).

Your second definition for the term Instance, I believe, is not good, -- where is it taken from? Here, as a user I care about interface and correct results, not about performance.

The name of a method is essential in order to understand what the system does. Now, v5.3 states that there are 0 instances of the Character in it. This is not true. We could rename the method, register a bug for the X release, or why not signal an exception  (#NotImplemented)? Because as it stands now, class Character does not know how to respond to a question about its instances but instead it claims to know and gives the incorrect answer.

regards,
Vaidotas 


On Sun, Mar 1, 2020 at 7:07 AM K K Subbu <[hidden email]> wrote:
On 01/03/20 1:41 AM, Vaidotas Didžbalis wrote:
> Thank you for your explanations, but ... but we have characters in the
> image. Having a characters in the image means that Character has
> instances. If alInstances method cannot report about them, it shall fire
> exception perhaps, or, name allInstances must be changed to something
> else, isn't it?

Instance has two meanings.

* the first one is as you explain it. This is usually the meaning
intended in all textbooks and applies to the overall object model (e.g.
$a isKindOf: Object is true).

* The second one is an object allocated in memory and is the one of most
interest in practice. Such objects need memory allocation, reference
counting and garbage collection services. The method allInstances uses
the word instances in the latter sense. Immediate objects don't need
these services, so they are not considered. (e.g. $a class
isImmediateClass is true).

This is like calling 45, 045 or 0045 as two digit numbers because
leading zeros are not significant in practice.

Could you explain the context behind your question?

Regards .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Character allInstances size=0 for 5.3 latest

K K Subbu
On 02/03/20 11:14 PM, Vaidotas Didžbalis wrote:
> Your second definition for the term Instance, I believe, is not good, --
> where is it taken from? Here, as a user I care about interface and
> correct results, not about performance.

Behavior>>allInstances method iterates through objects *in memory* using
someInstance and nextInstance primitives. Immediate objects are
cardinals and not ordinals, so nextInstance does not apply to them.

See the methods primitiveSomeInstance and primitiveNextInstance in VMMaker.

When primitiveSomeInstance returns nil, it means there are no instances
*in memory*.

> The name of a method is essential in order to understand what the system
> does. Now, v5.3 states that there are 0 instances of the Character in
> it. This is not true.

It is not true only by your definition of instance, but not as per VM
interpretation. The VM implementor has opted to exclude immediate
objects from consideration for pragmatic reasons.

Semantically the arithmetic operation a+b may be defined for all a, b
but pragmatics can limit this to modulo arithmetic.

> We could rename the method, register a bug for the
> X release, or why not signal an exception  (#NotImplemented)? Because as
> it stands now, class Character does not know how to respond to a
> question about its instances but instead it claims to know and gives the
> incorrect answer.
It is possible to iterate through all oops to find instances of
Characters to conform to your definition. This would be an expensive
operation. But what pragmatic purpose will be served? The juice has to
be worth the squeeze.

Regards .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners