タグ
Reading Gauche のタグについてな項のモディファイ中。いっちゃん最後の_Heap object_では以下な記述をしてます。
- 末端 3 bit が 111
- ペアと flonums 以外の heap-allocated なオブジェクトの最初のワードにのみ、との記述あり
- 末端 3 bit をマスクして ScmClass なポインタに、との事?
ScmHeaderRec 構造体の定義は gauche.h にて以下。
/* A common header for heap-allocated objects */ typedef struct ScmHeaderRec { ScmByte *tag; /* private. should be accessed only via SCM_CLASS_OF and SCM_SET_CLASS macros. */ } ScmHeader; #define SCM_HEADER ScmHeader hdr /* for declaration */
tag 属性へのアクセサは SCM_CLASS_OF と SCM_SET_CLASS マクロ限定とある。む、コメントに_A common header for heap-allocated objects_とあるな。
何故に
8 byte 単位? って思ったんですが例えば以下な heap-allocated object な定義があったとしても
struct ScmXXXRec { SCM_HEADER; unsigned char c; };
構造体オブジェクト自体は 8 bytes を消費するのか。あら? そんな単純な計算で良いのかなぁ。必ず 8 byte 境界になる所以が分からんな、と言いつつ直上なコメントにそれっぽい記述あり。
/* We use a pointer to the class structure (with low-bit tag) as the generic type tag. NB: The ScmClass structure is always aligned on 8-byte boundary, so +7 makes the tag's lower 3 bits '111'. Such pattern never appears in tagged pointer, so we can distinguish heap allocated objects from ScmPair. */ #define SCM_CLASS2TAG(klass) ((ScmByte*)(klass) + 7)
ええと、ScmClass 構造体は常に 8-byte 境界で云々、という記述があるな。ScmClass な定義を M-t してみたら以下がナニ。
/* * The class structure. ScmClass is actually a subclass of ScmObj. */ typedef struct ScmClassRec ScmClass;
ScmClassRec 構造体の定義の直上なコメントが以下。
/* We need all class structures be aligned on (at least) 8-byte boundary to make our tagging scheme work. Dynamically allocated objects are *always* 8-byte aligned due to Boehm GC's architecture. However, we found that statically allocated class structures can be placed 4-byte boundary on some 32bit systems if we started ScmClassRec with SCM_INSTANCE_HEADER. The following union is the trick to ensure 8-byte alighment on such systems. */
Boehm GC マターで 8 byte 境界になるのか。ただし静的に確保されたクラスのナニは 32bit なソレでは 4 byte 境界になるので云々とあるな。
とりあえず
今日は微妙。libgauche 云々もメモッておきたくはあるのですがどうなるか。