ObjFW  Changes On Branch e0b1a90547e791ee

Changes In Branch tagged-pointers Through [e0b1a90547] Excluding Merge-Ins

This is equivalent to a diff from 1a4eba3a16 to e0b1a90547

2021-01-30
20:21
Revert apple-forwarding-*.S back to AT&T syntax check-in: a6eb951b8c user: js tags: trunk
2020-07-04
21:19
tests: Use \r instead of setting cursorColumn = 0 check-in: ba32166987 user: js tags: trunk
14:21
lookup-asm-x86_64-macho.S: Support tagged pointers check-in: 3f2a6306a3 user: js tags: tagged-pointers
13:59
lookup-asm-sparc64-elf.S: Non-PIC optimization check-in: e0b1a90547 user: js tags: tagged-pointers
13:09
RuntimeTests: Make certain versions of Clang happy check-in: 4461f85857 user: js tags: tagged-pointers
2020-07-01
21:32
Merge trunk into branch "tagged-pointers" check-in: 6d5cc25f0c user: js tags: tagged-pointers
21:06
apple-forwarding-x86_64.S: Don't use jmp short check-in: 1a4eba3a16 user: js tags: trunk
20:36
.travis.yml: Install devkitPro via gdebi check-in: 62ac2b0cad user: js tags: trunk

Modified src/runtime/Makefile from [19d76e27b3] to [578f05e231].

26
27
28
29
30
31
32

33
34
35
36
37
38
39
       misc.m			\
       property.m		\
       protocol.m		\
       selector.m		\
       sparsearray.m		\
       static-instances.m	\
       synchronized.m		\

       ${USE_SRCS_THREADS}
SRCS_THREADS = threading.m	\
	       ../mutex.m	\
	       ../once.m	\
	       ../tlskey.m
INCLUDES = ObjFWRT.h
includesubdir = ObjFWRT







>







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
       misc.m			\
       property.m		\
       protocol.m		\
       selector.m		\
       sparsearray.m		\
       static-instances.m	\
       synchronized.m		\
       tagged-pointer.m		\
       ${USE_SRCS_THREADS}
SRCS_THREADS = threading.m	\
	       ../mutex.m	\
	       ../once.m	\
	       ../tlskey.m
INCLUDES = ObjFWRT.h
includesubdir = ObjFWRT

Modified src/runtime/ObjFWRT.h from [439a147585] to [852e5138d0].

240
241
242
243
244
245
246




247
248
249
250
251
252
253
    objc_enumeration_mutation_handler_t _Nullable handler);
extern id _Nullable objc_constructInstance(Class _Nullable class_,
    void *_Nullable bytes);
extern void *_Nullable objc_destructInstance(id _Nullable object);
extern void *_Null_unspecified objc_autoreleasePoolPush(void);
extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
extern id _Nullable _objc_rootAutorelease(id _Nullable object);





/*
 * Used by the compiler, but can also be called manually.
 *
 * These declarations are also required to prevent Clang's implicit
 * declarations which include __declspec(dllimport) on Windows.
 */







>
>
>
>







240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
    objc_enumeration_mutation_handler_t _Nullable handler);
extern id _Nullable objc_constructInstance(Class _Nullable class_,
    void *_Nullable bytes);
extern void *_Nullable objc_destructInstance(id _Nullable object);
extern void *_Null_unspecified objc_autoreleasePoolPush(void);
extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
extern id _Nullable _objc_rootAutorelease(id _Nullable object);
extern int objc_registerTaggedPointerClass(Class _Nonnull class);
extern Class _Nullable object_getTaggedPointerClass(id _Nonnull object);
extern uintptr_t object_getTaggedPointerValue(id _Nonnull object);
extern id _Nullable objc_createTaggedPointer(int class, uintptr_t value);

/*
 * Used by the compiler, but can also be called manually.
 *
 * These declarations are also required to prevent Clang's implicit
 * declarations which include __declspec(dllimport) on Windows.
 */

Modified src/runtime/amiga-glue.m from [5dde941d59] to [3dbec0ba16].

795
796
797
798
799
800
801

































void __saveds
glue_objc_hashtable_free PPC_PARAMS(struct objc_hashtable *table)
{
	M68K_ARG(struct objc_hashtable *, table, a0)

	objc_hashtable_free(table);
}








































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
void __saveds
glue_objc_hashtable_free PPC_PARAMS(struct objc_hashtable *table)
{
	M68K_ARG(struct objc_hashtable *, table, a0)

	objc_hashtable_free(table);
}

int
glue_objc_registerTaggedPointerClass PPC_PARAMS(Class class)
{
	M68K_ARG(Class, class, a0)

	return objc_registerTaggedPointerClass(class);
}

Class
glue_object_getTaggedPointerClass PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return object_getTaggedPointerClass(object);
}

uintptr_t
glue_object_getTaggedPointerValue PPC_PARAMS(id object)
{
	M68K_ARG(id, object, a0)

	return object_getTaggedPointerValue(object);
}

id
glue_objc_createTaggedPointer PPC_PARAMS(int class, uintptr_t value)
{
	M68K_ARG(int, class, d0)
	M68K_ARG(uintptr_t, value, d1)

	return objc_createTaggedPointer(class, value);
}

Modified src/runtime/amiga-library.m from [3100a40497] to [7a20b4c30e].

143
144
145
146
147
148
149




150
151
152
153
154
155
156
extern void glue_objc_autoreleasePoolPop(void);
extern id glue__objc_rootAutorelease(void);
extern struct objc_hashtable *glue_objc_hashtable_new(void);
extern void glue_objc_hashtable_set(void);
extern void *glue_objc_hashtable_get(void);
extern void glue_objc_hashtable_delete(void);
extern void glue_objc_hashtable_free(void);





#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;







>
>
>
>







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
extern void glue_objc_autoreleasePoolPop(void);
extern id glue__objc_rootAutorelease(void);
extern struct objc_hashtable *glue_objc_hashtable_new(void);
extern void glue_objc_hashtable_set(void);
extern void *glue_objc_hashtable_get(void);
extern void glue_objc_hashtable_delete(void);
extern void glue_objc_hashtable_free(void);
extern int glue_objc_registerTaggedPointerClass(void);
extern Class _Nullable glue_object_getTaggedPointerClass(void);
extern uintptr_t glue_object_getTaggedPointerValue(void);
extern id _Nullable glue_objc_createTaggedPointer(void);

#ifdef OF_MORPHOS
const ULONG __abox__ = 1;
#endif
struct ExecBase *SysBase;
struct objc_libc libc;
FILE *stdout;
669
670
671
672
673
674
675




676
677
678
679
680
681
682
	(CONST_APTR)glue_objc_autoreleasePoolPop,
	(CONST_APTR)glue__objc_rootAutorelease,
	(CONST_APTR)glue_objc_hashtable_new,
	(CONST_APTR)glue_objc_hashtable_set,
	(CONST_APTR)glue_objc_hashtable_get,
	(CONST_APTR)glue_objc_hashtable_delete,
	(CONST_APTR)glue_objc_hashtable_free,




	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif
};
#pragma GCC diagnostic pop








>
>
>
>







673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
	(CONST_APTR)glue_objc_autoreleasePoolPop,
	(CONST_APTR)glue__objc_rootAutorelease,
	(CONST_APTR)glue_objc_hashtable_new,
	(CONST_APTR)glue_objc_hashtable_set,
	(CONST_APTR)glue_objc_hashtable_get,
	(CONST_APTR)glue_objc_hashtable_delete,
	(CONST_APTR)glue_objc_hashtable_free,
	(CONST_APTR)glue_objc_registerTaggedPointerClass,
	(CONST_APTR)glue_object_getTaggedPointerClass,
	(CONST_APTR)glue_object_getTaggedPointerValue,
	(CONST_APTR)glue_objc_createTaggedPointer,
	(CONST_APTR)-1,
#ifdef OF_MORPHOS
	(CONST_APTR)FUNCARRAY_END
#endif
};
#pragma GCC diagnostic pop

Modified src/runtime/amigaos3.sfd from [c645261c7f] to [a0d1b4c012].

85
86
87
88
89
90
91





92
id _Nullable glue__objc_rootAutorelease(id _Nullable object)(a0)
* The following functions are private! Don't use!
struct objc_hashtable *_Nonnull glue_objc_hashtable_new(objc_hashtable_hash_func hash, objc_hashtable_equal_func equal, uint32_t size)(a0,a1,d0)
void glue_objc_hashtable_set(struct objc_hashtable *_Nonnull table, const void *_Nonnull key, const void *_Nonnull object)(a0,a1,a2)
void *_Nullable glue_objc_hashtable_get(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_delete(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_free(struct objc_hashtable *_Nonnull table)(a0)





==end







>
>
>
>
>

85
86
87
88
89
90
91
92
93
94
95
96
97
id _Nullable glue__objc_rootAutorelease(id _Nullable object)(a0)
* The following functions are private! Don't use!
struct objc_hashtable *_Nonnull glue_objc_hashtable_new(objc_hashtable_hash_func hash, objc_hashtable_equal_func equal, uint32_t size)(a0,a1,d0)
void glue_objc_hashtable_set(struct objc_hashtable *_Nonnull table, const void *_Nonnull key, const void *_Nonnull object)(a0,a1,a2)
void *_Nullable glue_objc_hashtable_get(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_delete(struct objc_hashtable *_Nonnull table, const void *_Nonnull key)(a0,a1)
void glue_objc_hashtable_free(struct objc_hashtable *_Nonnull table)(a0)
* Public functions again
int glue_objc_registerTaggedPointerClass(Class _Nonnull class_)(a0)
Class _Nullable glue_object_getTaggedPointerClass(id _Nonnull object)(a0)
uintptr_t glue_object_getTaggedPointerValue(id _Nonnull object)(a0)
id _Nullable glue_objc_createTaggedPointer(int class_, uintptr_t value)(d0,d1)
==end

Modified src/runtime/class.m from [959b2ef399] to [02bad041ab].

842
843
844
845
846
847
848



849
850
851
852
853
854
855
object_getClass(id object_)
{
	struct objc_object *object;

	if (object_ == nil)
		return Nil;




	object = (struct objc_object *)object_;

	return object->isa;
}

Class
object_setClass(id object_, Class class)







>
>
>







842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
object_getClass(id object_)
{
	struct objc_object *object;

	if (object_ == nil)
		return Nil;

	if (object_isTaggedPointer(object_))
		return object_getTaggedPointerClass(object_);

	object = (struct objc_object *)object_;

	return object->isa;
}

Class
object_setClass(id object_, Class class)

Modified src/runtime/linklib/linklib.m from [141357802d] to [b0ccaf3f6e].

703
704
705
706
707
708
709
























}

void
objc_hashtable_free(struct objc_hashtable *table)
{
	glue_objc_hashtable_free(table);
}































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
}

void
objc_hashtable_free(struct objc_hashtable *table)
{
	glue_objc_hashtable_free(table);
}

int
objc_registerTaggedPointerClass(Class class)
{
	return glue_objc_registerTaggedPointerClass(class);
}

Class
object_getTaggedPointerClass(id object)
{
	return glue_object_getTaggedPointerClass(object);
}

uintptr_t
object_getTaggedPointerValue(id object)
{
	return glue_object_getTaggedPointerValue(object);
}

id
objc_createTaggedPointer(int class, uintptr_t value)
{
	return objc_createTaggedPointer(class, value);
}

Modified src/runtime/lookup-asm/lookup-asm-sparc64-elf.S from [ca8ce4890a] to [b777f33d5b].

24
25
26
27
28
29
30


31
32
33
34
35
36
37
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	brz,pn	%o0, ret_nil


	 nop

	ldx	[%o0], %o2
	ldx	[%o2 + 64], %o2

.Lmain_\name:
#ifdef OF_SELUID24







>
>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	brz,pn	%o0, ret_nil
	 and	%o0, 1, %o2
	brnz,pn	%o2, .Ltagged_pointer_\name
	 nop

	ldx	[%o0], %o2
	ldx	[%o2 + 64], %o2

.Lmain_\name:
#ifdef OF_SELUID24
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

























66
67
68
69
70
71
72

#ifdef OF_SELUID24
	ldx	[%o2 + %o3], %o2
#endif
	ldx	[%o2 + %o4], %o2
	ldx	[%o2 + %o5], %o2

	cmp	%o2, 0
	be,pn	%xcc, 0f
	 nop

	retl
	 mov	%o2, %o0

0:
	mov	%o7, %g1
	call	\not_found
	 mov	%g1, %o7

























.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	%o0, %o2







|
<









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







50
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

#ifdef OF_SELUID24
	ldx	[%o2 + %o3], %o2
#endif
	ldx	[%o2 + %o4], %o2
	ldx	[%o2 + %o5], %o2

	brz,pn	%o2, 0f

	 nop

	retl
	 mov	%o2, %o0

0:
	mov	%o7, %g1
	call	\not_found
	 mov	%g1, %o7

.Ltagged_pointer_\name:
	and	%o0, 0xE, %o2
	sll	%o2, 2, %o2

#ifdef OF_PIC
	mov	%o7, %g1
	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - 4), %o3
	call	0f
	 or	%o3, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o3
0:
	add	%o7, %o3, %o3
	mov	%g1, %o7

	sethi	%hi(objc_tagged_pointer_classes), %o0
	or	%o0, %lo(objc_tagged_pointer_classes), %o0
	ldx	[%o3 + %o0], %o0
#else
	sethi	%hi(objc_tagged_pointer_classes), %o0
	or	%o0, %lo(objc_tagged_pointer_classes), %o0
#endif
	ldx	[%o0 + %o2], %o2
	ba	.Lmain_\name
	 ldx	[%o2 + 64], %o2

.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	%o0, %o2
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

ret_nil:
#ifdef OF_PIC
	mov	%o7, %g1

	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - 4), %o1
	call	0f
	 add	%o1, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o1
0:
	add	%o7, %o1, %o1

	sethi	%hi(nil_method), %o0
	or	%o0, %lo(nil_method), %o0

	jmpl	%g1 + 8, %g0







|







114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

ret_nil:
#ifdef OF_PIC
	mov	%o7, %g1

	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - 4), %o1
	call	0f
	 or	%o1, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o1
0:
	add	%o7, %o1, %o1

	sethi	%hi(nil_method), %o0
	or	%o0, %lo(nil_method), %o0

	jmpl	%g1 + 8, %g0

Modified src/runtime/lookup-asm/lookup-asm-x86-elf.S from [582b619bd5] to [6468f2e74c].

29
30
31
32
33
34
35



36
37
38
39
40
41
42
.section .text
.macro generate_lookup name not_found
\name:
	mov	edx, [esp+4]
	test	edx, edx
	jz	short ret_nil




	mov	edx, [edx]
	mov	edx, [edx+32]

.Lmain_\name:
	mov	eax, [esp+8]

#ifdef OF_SELUID24







>
>
>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
.section .text
.macro generate_lookup name not_found
\name:
	mov	edx, [esp+4]
	test	edx, edx
	jz	short ret_nil

	bt	edx, 0
	jc	short .Ltagged_pointer_\name

	mov	edx, [edx]
	mov	edx, [edx+32]

.Lmain_\name:
	mov	eax, [esp+8]

#ifdef OF_SELUID24
54
55
56
57
58
59
60














61
62
63
64
65
66
67
	ret

0:
	call	get_eip
	add	eax, offset _GLOBAL_OFFSET_TABLE_
	lea	eax, [eax+\not_found@GOTOFF]
	jmp	eax














.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	edx, [esp+4]







>
>
>
>
>
>
>
>
>
>
>
>
>
>







57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
	ret

0:
	call	get_eip
	add	eax, offset _GLOBAL_OFFSET_TABLE_
	lea	eax, [eax+\not_found@GOTOFF]
	jmp	eax

.Ltagged_pointer_\name:
	and	dl, 0xF
	shr	dl, 1
	movzx	edx, dl

	call	get_eip
	add	eax, offset _GLOBAL_OFFSET_TABLE_

	lea	eax, [eax+objc_tagged_pointer_classes@GOTOFF]
	mov	edx, [eax+edx*4]
	mov	edx, [edx+32]

	jmp	short .Lmain_\name
.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	edx, [esp+4]

Modified src/runtime/lookup-asm/lookup-asm-x86-win32.S from [44cfb2c923] to [6bf3eb314e].

27
28
29
30
31
32
33



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53




54



55

56
57
58
59
60
61
62
.section .text
.macro generate_lookup name not_found
\name:
	mov	edx, [esp+4]
	test	edx, edx
	jz	short ret_nil




	mov	edx, [edx]
	mov	edx, [edx+32]

.Lmain_\name:
	mov	eax, [esp+8]

#ifdef OF_SELUID24
	movzx	ecx, byte ptr [eax+2]
	mov	edx, [edx+ecx*4]
#endif
	movzx	ecx, byte ptr [eax+1]
	mov	edx, [edx+ecx*4]
	movzx	ecx, byte ptr [eax]
	mov	eax, [edx+ecx*4]

	test	eax, eax
	jz	short 0f

	ret





0:



	jmp	\not_found

.endm

.macro generate_lookup_super name lookup
\name:
	mov	edx, [esp+4]
	mov	eax, [edx]
	test	eax, eax







>
>
>
















|



>
>
>
>
|
>
>
>
|
>







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
.section .text
.macro generate_lookup name not_found
\name:
	mov	edx, [esp+4]
	test	edx, edx
	jz	short ret_nil

	bt	edx, 0
	jc	short .Ltagged_pointer_\name

	mov	edx, [edx]
	mov	edx, [edx+32]

.Lmain_\name:
	mov	eax, [esp+8]

#ifdef OF_SELUID24
	movzx	ecx, byte ptr [eax+2]
	mov	edx, [edx+ecx*4]
#endif
	movzx	ecx, byte ptr [eax+1]
	mov	edx, [edx+ecx*4]
	movzx	ecx, byte ptr [eax]
	mov	eax, [edx+ecx*4]

	test	eax, eax
	jz	\not_found

	ret

.Ltagged_pointer_\name:
	and	dl, 0xF
	shr	dl, 1
	movzx	edx, dl

	mov	eax, offset _objc_tagged_pointer_classes
	mov	edx, [eax+edx*4]
	mov	edx, [edx+32]

	jmp	short .Lmain_\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	edx, [esp+4]
	mov	eax, [edx]
	test	eax, eax

Modified src/runtime/lookup-asm/lookup-asm-x86_64-elf.S from [d030c5228c] to [00fefd9a7f].

28
29
30
31
32
33
34



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53











54
55
56
57
58
59
60

.section .text
.macro generate_lookup name not_found
\name:
	test	rdi, rdi
	jz	short ret_nil




	mov	r8, [rdi]
	mov	r8, [r8+64]

.Lmain_\name:
	mov	rax, [rsi]
	movzx	ecx, ah
	movzx	edx, al
#ifdef OF_SELUID24
	shr	eax, 16

	mov	r8,  [r8+rax*8]
#endif
	mov	r8,  [r8+rcx*8]
	mov	rax, [r8+rdx*8]

	test	rax, rax
	jz	short \not_found@PLT

	ret











.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	r8, rdi







>
>
>



















>
>
>
>
>
>
>
>
>
>
>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

.section .text
.macro generate_lookup name not_found
\name:
	test	rdi, rdi
	jz	short ret_nil

	bt	edi, 0
	jc	short .Ltagged_pointer_\name

	mov	r8, [rdi]
	mov	r8, [r8+64]

.Lmain_\name:
	mov	rax, [rsi]
	movzx	ecx, ah
	movzx	edx, al
#ifdef OF_SELUID24
	shr	eax, 16

	mov	r8,  [r8+rax*8]
#endif
	mov	r8,  [r8+rcx*8]
	mov	rax, [r8+rdx*8]

	test	rax, rax
	jz	short \not_found@PLT

	ret

.Ltagged_pointer_\name:
	and	dil, 0xF
	shr	dil, 1
	movzx	r8, dil

	mov	rax, [rip+objc_tagged_pointer_classes@GOTPCREL]
	mov	r8, [rax+r8*8]
	mov	r8, [r8+64]

	jmp	short .Lmain_\name
.type \name, %function
.size \name, .-\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	r8, rdi

Modified src/runtime/lookup-asm/lookup-asm-x86_64-win64.S from [47f8ccf7d6] to [069968302a].

23
24
25
26
27
28
29
30
31
32



33
34
35
36
37
38
39
.globl objc_msg_lookup_stret
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	test	%rcx, %rcx
	jz	short ret_nil




	mov	r8, [rcx]
	mov	r8, [r8+56]

.Lmain_\name:
	mov	r10, rcx
	mov	r11, rdx








|


>
>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
.globl objc_msg_lookup_stret
.globl objc_msg_lookup_super
.globl objc_msg_lookup_super_stret

.section .text
.macro generate_lookup name not_found
\name:
	test	rcx, rcx
	jz	short ret_nil

	bt	ecx, 0
	jc	short .Ltagged_pointer_\name

	mov	r8, [rcx]
	mov	r8, [r8+56]

.Lmain_\name:
	mov	r10, rcx
	mov	r11, rdx

53
54
55
56
57
58
59











60
61
62
63
64
65
66

	ret

0:
	mov	rcx, r10
	mov	rdx, r11
	jmp	\not_found











.endm

.macro generate_lookup_super name lookup
\name:
	mov	r8, rcx
	mov	rcx, [rcx]
	test	rcx, rcx







>
>
>
>
>
>
>
>
>
>
>







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

	ret

0:
	mov	rcx, r10
	mov	rdx, r11
	jmp	\not_found

.Ltagged_pointer_\name:
	and	cl, 0xF
	shr	cl, 1
	movzx	r8, cl

	mov	rax, offset objc_tagged_pointer_classes
	mov	r8, [rax+r8*8]
	mov	r8, [r8+56]

	jmp	short .Lmain_\name
.endm

.macro generate_lookup_super name lookup
\name:
	mov	r8, rcx
	mov	rcx, [rcx]
	test	rcx, rcx

Modified src/runtime/morphos-clib.h from [cfb2b6af7e] to [003198598f].

75
76
77
78
79
80
81
82
83
84
85
86





const char *glue_property_getName(objc_property_t);
char *glue_property_copyAttributeValue(objc_property_t, const char *);
void *glue_objc_destructInstance(id);
void *glue_objc_autoreleasePoolPush(void);
void glue_objc_autoreleasePoolPop(void *);
id glue__objc_rootAutorelease(id);
/* The following functions are private! Don't use! */
struct objc_hashtable *glue_objc_hashtable_new(objc_hashtable_hash_func hash, objc_hashtable_equal_func equal, uint32_t size);
void glue_objc_hashtable_set(struct objc_hashtable *table, const void *key, const void *object);
void *glue_objc_hashtable_get(struct objc_hashtable *table, const void *key);
void glue_objc_hashtable_delete(struct objc_hashtable *table, const void *key);
void glue_objc_hashtable_free(struct objc_hashtable *table);












|
|
|
|
|
>
>
>
>
>
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const char *glue_property_getName(objc_property_t);
char *glue_property_copyAttributeValue(objc_property_t, const char *);
void *glue_objc_destructInstance(id);
void *glue_objc_autoreleasePoolPush(void);
void glue_objc_autoreleasePoolPop(void *);
id glue__objc_rootAutorelease(id);
/* The following functions are private! Don't use! */
struct objc_hashtable *glue_objc_hashtable_new(objc_hashtable_hash_func, objc_hashtable_equal_func, uint32_t);
void glue_objc_hashtable_set(struct objc_hashtable *, const void *, const void *);
void *glue_objc_hashtable_get(struct objc_hashtable *, const void *);
void glue_objc_hashtable_delete(struct objc_hashtable *, const void *);
void glue_objc_hashtable_free(struct objc_hashtable *);
/* Public functions again */
int glue_objc_registerTaggedPointerClass(Class);
Class _Nullable glue_object_getTaggedPointerClass(id);
uintptr_t glue_object_getTaggedPointerValue(id);
id glue_objc_createTaggedPointer(int, uintptr_t);

Modified src/runtime/morphos.fd from [f7d065769a] to [705f1d62db].

83
84
85
86
87
88
89





90
glue__objc_rootAutorelease(object)(sysv,r12base)
* The following functions are private! Don't use!
glue_objc_hashtable_new(hash,equal,size)(sysv,r12base)
glue_objc_hashtable_set(table,key,object)(sysv,r12base)
glue_objc_hashtable_get(table,key)(sysv,r12base)
glue_objc_hashtable_delete(table,key)(sysv,r12base)
glue_objc_hashtable_free(table)(sysv,r12base)





##end







>
>
>
>
>

83
84
85
86
87
88
89
90
91
92
93
94
95
glue__objc_rootAutorelease(object)(sysv,r12base)
* The following functions are private! Don't use!
glue_objc_hashtable_new(hash,equal,size)(sysv,r12base)
glue_objc_hashtable_set(table,key,object)(sysv,r12base)
glue_objc_hashtable_get(table,key)(sysv,r12base)
glue_objc_hashtable_delete(table,key)(sysv,r12base)
glue_objc_hashtable_free(table)(sysv,r12base)
* Public functions again
glue_objc_registerTaggedPointerClass(class_)(sysv,r12base)
glue_object_getTaggedPointerClass(object)(sysv,r12base)
glue_object_getTaggedPointerValue(object)(sysv,r12base)
glue_objc_createTaggedPointer(class_,value)(sysv,r12base)
##end

Modified src/runtime/private.h from [82de8c2339] to [e3fff27493].

331
332
333
334
335
336
337








338
339
340
341
342
343
344
#else
	uint8_t i = idx >> 8;
	uint8_t j = idx;

	return dtable->buckets[i]->buckets[j];
#endif
}









#if defined(OF_ELF)
# if defined(OF_X86_64) || defined(OF_X86) || defined(OF_POWERPC) || \
    defined(OF_ARM64) || defined(OF_ARM) || \
    defined(OF_MIPS64_N64) || defined(OF_MIPS) || \
    defined(OF_SPARC64) || defined(OF_SPARC)
#  define OF_ASM_LOOKUP







>
>
>
>
>
>
>
>







331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#else
	uint8_t i = idx >> 8;
	uint8_t j = idx;

	return dtable->buckets[i]->buckets[j];
#endif
}

static inline bool
object_isTaggedPointer(id _Nullable object)
{
	uintptr_t pointer = (uintptr_t)object;

	return pointer & 1;
}

#if defined(OF_ELF)
# if defined(OF_X86_64) || defined(OF_X86) || defined(OF_POWERPC) || \
    defined(OF_ARM64) || defined(OF_ARM) || \
    defined(OF_MIPS64_N64) || defined(OF_MIPS) || \
    defined(OF_SPARC64) || defined(OF_SPARC)
#  define OF_ASM_LOOKUP

Added src/runtime/tagged-pointer.m version [eeba4c306c].















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
 *               2018, 2019, 2020
 *   Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "ObjFWRT.h"

#import "private.h"

#define TAGGED_POINTER_BITS 4
#define NUM_TAGGED_POINTER_CLASSES (1 << (TAGGED_POINTER_BITS - 1))

Class objc_tagged_pointer_classes[NUM_TAGGED_POINTER_CLASSES];
static int taggedPointerClassesCount;

int
objc_registerTaggedPointerClass(Class class)
{
	int i;

	objc_global_mutex_lock();

	if (taggedPointerClassesCount == NUM_TAGGED_POINTER_CLASSES) {
		objc_global_mutex_unlock();
		return -1;
	}

	i = taggedPointerClassesCount++;
	objc_tagged_pointer_classes[i] = class;

	objc_global_mutex_unlock();

	return i;
}

Class
object_getTaggedPointerClass(id object)
{
	uintptr_t pointer = (uintptr_t)object;

	pointer &= (1 << TAGGED_POINTER_BITS) - 1;
	pointer >>= 1;

	if (pointer >= NUM_TAGGED_POINTER_CLASSES)
		return Nil;

	return objc_tagged_pointer_classes[pointer];
}

uintptr_t
object_getTaggedPointerValue(id object)
{
	uintptr_t pointer = (uintptr_t)object;

	pointer >>= TAGGED_POINTER_BITS;

	return pointer;
}

id
objc_createTaggedPointer(int class, uintptr_t value)
{
	uintptr_t pointer;

	if (class < 0 || class >= NUM_TAGGED_POINTER_CLASSES)
		return nil;

	if (value > (UINTPTR_MAX >> TAGGED_POINTER_BITS))
		return nil;

	pointer = (class << 1) | 1;
	pointer |= (value << TAGGED_POINTER_BITS);

	return (id)pointer;
}

Modified tests/RuntimeTests.m from [1191342e90] to [33b8900615].

63
64
65
66
67
68
69





70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85



















86
87
88
89

@implementation TestsAppDelegate (RuntimeTests)
- (void)runtimeTests
{
	void *pool = objc_autoreleasePoolPush();
	RuntimeTest *rt = [[[RuntimeTest alloc] init] autorelease];
	OFString *t, *foo;






	EXPECT_EXCEPTION(@"Calling a non-existent method via super",
	    OFNotImplementedException, [rt superTest])

	TEST(@"Calling a method via a super with self == nil",
	    [rt nilSuperTest] == nil)

	t = [OFMutableString stringWithString: @"foo"];
	foo = @"foo";

	[rt setFoo: t];
	TEST(@"copy, nonatomic properties", [rt.foo isEqual: foo] &&
	    rt.foo != foo && rt.foo.retainCount == 1)

	rt.bar = t;
	TEST(@"retain, atomic properties", rt.bar == t && t.retainCount == 3)




















	objc_autoreleasePoolPop(pool);
}
@end







>
>
>
>
>
















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

@implementation TestsAppDelegate (RuntimeTests)
- (void)runtimeTests
{
	void *pool = objc_autoreleasePoolPush();
	RuntimeTest *rt = [[[RuntimeTest alloc] init] autorelease];
	OFString *t, *foo;
#ifdef OF_OBJFW_RUNTIME
	int cid1, cid2;
	uintmax_t value;
	id object;
#endif

	EXPECT_EXCEPTION(@"Calling a non-existent method via super",
	    OFNotImplementedException, [rt superTest])

	TEST(@"Calling a method via a super with self == nil",
	    [rt nilSuperTest] == nil)

	t = [OFMutableString stringWithString: @"foo"];
	foo = @"foo";

	[rt setFoo: t];
	TEST(@"copy, nonatomic properties", [rt.foo isEqual: foo] &&
	    rt.foo != foo && rt.foo.retainCount == 1)

	rt.bar = t;
	TEST(@"retain, atomic properties", rt.bar == t && t.retainCount == 3)

#ifdef OF_OBJFW_RUNTIME
	if (sizeof(uintptr_t) == 8)
		value = 0xDEADBEEFDEADBEF;
	else if (sizeof(uintptr_t) == 4)
		value = 0xDEADBEF;
	else
		abort();

	TEST(@"Tagged pointers",
	    (cid1 = objc_registerTaggedPointerClass([OFString class])) != -1 &&
	    (cid2 = objc_registerTaggedPointerClass([OFNumber class])) != -1 &&
	    (object = objc_createTaggedPointer(cid2, (uintptr_t)value)) &&
	    object_getTaggedPointerClass(object) == [OFNumber class] &&
	    [object class] == [OFNumber class] &&
	    object_getTaggedPointerValue(object) == value &&
	    objc_createTaggedPointer(cid2, UINTPTR_MAX >> 4) != nil &&
	    objc_createTaggedPointer(cid2, (UINTPTR_MAX >> 4) + 1) == nil)
#endif

	objc_autoreleasePoolPop(pool);
}
@end