Re: [NTLK] Heap Sucker (long)

From: Robert Benschop (rbenschop_at_mac.com)
Date: Tue Feb 26 2002 - 14:21:04 EST


on 26-02-2002 6:11, Bradford Schmidt at brad_at_jojoro.com wrote:

> 2 - How does the heap management work, anyway?

Well you asked for it, here you go.

First of all you could go to The Newton Heap MiniFAQ
http://www.geocities.com/Paris/8382/FAQ.html

Victor and the other FAQ maintainers, I checked the FAQ and didn't see a
link to these pages, an idea to ad it ?

Second I'll post an answer of the master of the Newton universe, maybe the
last developer in this world that has at least in part an overview of the
Newton OS, I'd like a big hand for Paul Guyot....

take it away Paul:

From: Paul Guyot

>| But what did help was when I realized that the system software for my 2100
>| was not the most updated one (I think it was 717006 or something)...on
>| upgrading it to the new 710031 version, Avi's instantly presented me with
>| around 380000 K !!!!!
>
>Hmmm... how do these compare to ROM version 2.1 (717260), anyway?

OK, let me explain that.

Like any other computer, the Newton uses four kind of memory (corresponding
to their usage).

(a) Read-Only memory, to hold information never to forget/change on the
Newton. Like any other commercial computer, this is assumed by Factory-ROM
chips (built by Sharp), except with prototype programmable cards equipped
with Flash (Greg Christie from Apple still has one). The particularity of
Newton OS is that it is entirely in ROM.
MP 2x00 has 8 megs in standard (on the card). The maximum is 24 megs (16
for Chip select 0 and 8 for chipselect 1).

(b) Read/Write persistent memory, to save your data across reboots. On
Mp2x00 it is assumed by Flash. Desktop computers use magnetic/optic devices
instead (like my SCSI 18.7 Go Hard Drive), because of the cost.
Newton MessagePad can increase the basic 4 megs by PCMCIA cards. The
drivers available accept only linear cards. There can also be 8 megs of
flash (used as RW persistent memory) on the MP 2x00 extension card
(chipselect 1)

(c) Read/Write non persistent memory. This is basically used for programs
while they run.
On most OSes, the program or parts of it are loaded in this memory, while
Virtual Memory-able OSes may load it only thru the Virtual Memory process.
So does MacOS with CFM application (most PowerPC code and some 68k code).
The Newton OS is a little bit different because all storage is mapped in
memory. (hence the absence of ATA driver since Linear works like this (1
address - 1 data chunk (4 bytes in this case)) while ATA is a disk
interface (several addresses for I/O and a request, a buffer where a block
or sector is loaded)).
Therefore, whatever the size of the package, most of it won't be loaded
into memory. This is crucial because with this mechanism, most of the ROM
is not loaded in memory although it includes programs (on not only OS
library). In a way, there is no real virtual memory like on every other
virtual memory-able OS.
In fact, you cannot increase available RAM by the Virtual Memory magic. VM
only applies to already stored data (basically virtual binary objects which
includes packages and user VBO since OS 2.0)

(d) I/O memory. These are addresses which when accessed (i.e. when the
processor presents them on the address bus) trigger some external
mechanism. The mechanism may look at the write/read line of the processor
and/or data.
This way you can tell the drive of the Apple ][ to run, and the head to go
to a specific track/sector. Today, most of theses commands are accessed
thru intelligent devices the processor communicate with, but the
communication is mostly done with this method.
(the other method a processor can communicate with external devices is
three-state buffer. It is what happens with Apple ][ screen memory: the
processor changes the memory which is read by the video device to output it
to the screen).

The Newton Message Pads are once again different. (at least MP 2x00). The
chips which talks directly to the processor are just the ROM card and some
rare elements. RAM, Flash, Cards, Serial Number, Tablet, Sound, Serial
ports, etc... are for most of them accessed thru a specific chip which is
at the heart of the MP. Open your MP (well, this is purely rhetorical,
don't), and you'll see: it's even bigger than the processor. (it is the
famous Cirrus chipset developed for the Newton MP2x00 only).
The processor talks at the bus speed. Depending on the cache and pipe
capabilities, the bus speed is as important as the general clock speed.
In the case of the Newton MP2x00, the bus speed is at 12 MHz. But the
Strong ARM has important cache and pipe capabilities.

Well, this was hardware. Let's talk about software.

Most OSes organize the Read/Write non persistent memory (remember, this is
the function because of the specificity, some RAM chips can be used as
persistent memory (is indeed used) like in the MP1x0, the SRAM cards or the
persistent RAM on most computers (with a battery to save their content)
like Macintoshes where you have some settings like the Machine Ethernet ID
or the mouse speed (this RAM is called PRAM like Persistent RAM...)).
This organization depends on the way bits of code and data interface each
other.

On most multiple programs OSes, this memory is organized into heaps. Each
program has one heap. There are some heaps for additional tasks.
The interest is that when the program closes, heap is emptied, and the
memory used can be used for another program. The other advantage is that
the heap is sometimes protected, i.e. other program cannot see and/or
change what's in another program's heap. In all cases, except if
programmers are *very* clean, the OS must label each chunk of memory it
allocates for a program in order to release it for another program's use
when this program closes without releasing all data. The same kind of
mechanism exists/should exist for files. It typically does on MacOS.

On Newton OS, there are several heaps. But what is special is that there is
a single heap for what we consider several programs: the Newton Script
heap. All Newton Script objects are together in a single heap. When a
program is closed (i.e. when it is removed/deleted/frozen), everything the
OS knows to belong to the program is removed. (basically, if it an
application, RemoveSlot(GetRoot(), kAppSymbol) plus the remove part once
the program played with it.
But some parts are not. This may be the goal of the developer or not. To
help disposal of these parts, there is a removescript, a routine called by
the OS to allow the program to do cleanup. This is not an easy task,
especially when dealing with some global data. Some programs (including
alt.rec...., but also HyperNewt, etc...) don't do a perfect cleaning. They
sometimes offer to restart.

If you ever enjoyed a -48221, this is it. As you remember, the packages are
mapped to the global 4 gigs the Strong ARM can access. (their address
starts with 6). A -48221 is triggered everytime a reference to an object
which was in this area (and cannot be found because the beginning of the
object points to vaccuum) is encountered.

The fact that all programs run under the same heap has both advantages and
disadvantages. Disadvantages are bad cleaning, non/bad protection [on
Newton OS, all programs are locked because they are not loaded into memory,
but changeable data is not locked and can be changed by any NS function].

The Newton OS is fully preemptive, but the Newton Script emulator is not
re-entrant, i.e. if two preemptive tasks run it, there may be problems
because in one task, the program may still believe some information correct
(especially data location) while the other changed it (in this case, a
garbage collect is catastrophic). It is linked with the fact that their is
one heap for NS.
The NS world is unique, and programs much their behave properly (some
bahavior may disturb other programs). In exchange, communicating with other
programs data is *very* easy. The OS relies heavily on the NS layer, but is
not entirely limited to it. It does not only because most of it is NS
objects.

The size of heaps are sometimes fixed or variable depending on the OS. All
heaps have a fixed size on NewtonOS. This has advantages and disadvantages.
The size of the NS heap is fixed at startup from a fixed value in ROM.
The ROM in MP2100 is the one programmed for MP2000. The size of NS Heap is
fixed according to 1 megs of RAM. Fortunately, Apple designed a system
update which changes this. This change is included in both updates 717260
(1997) and the new update we released, 710031. In these updates, the system
decides of the size of the NS heap according to the global RAM size.

Hence the change observed while updating to 710031. But this does not
reflect the global change.

In fact, I still wonder why the increase of the NS Heap size is so small
with Apple's Update, considering that the OS was fine with 1 megs shared
among all heaps. This is one of the things to change with the 10061 bug.
The best would be a variable heap size (we may extend the TUDomain class in
order to add this fonctionality / or work thru the implemented exception
mechanism).

Regards,

Paul

-- 
This is the Newtontalk mailinglist - http://www.newtontalk.net
To unsubscribe or manage: visit the above link or
	mailto:newtontalk-request_at_newtontalk.net?Subject=unsubscribe



This archive was generated by hypermail 2.1.2 : Sat Mar 02 2002 - 10:03:51 EST