1/*
2 * Copyright (c) 2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20//
21//  slop.m
22//  gctests
23//
24//  Created by Blaine Garst on 10/21/08.
25//  Copyright 2008-2009 Apple, Inc. All rights reserved.
26//
27// CONFIG GC -C99 -lauto
28
29#import <Foundation/Foundation.h>
30#import "auto_zone.h"
31
32@interface NotSoSmall : NSObject {
33    // 4 items per quantum, 3 quantum in TLC
34    long junk[12]; // overlap into next quantum by 1
35}
36@end
37
38@interface Bigger : NotSoSmall {
39    long junk2[3];  // just enough to flesh out allocation
40}
41@end
42
43@implementation NotSoSmall
44- init {
45    if (junk[13]) {
46        printf("found non-zero junk!\n");
47        exit(1);
48    }
49    return self;
50}
51
52@end
53@implementation Bigger
54
55- init {
56    [super init];
57    junk2[0] = 0x2342341;
58    junk2[1] = 0x2322232;
59    junk2[2] = 0x2342343;  // if these were objects they would leak when they came back as NotSoSmall
60    return self;
61}
62
63@end
64
65
66void test() {
67    for (int i = 0; i < 30; ++i) {
68        // allocate a bunch of Bigger
69        for (int j = 0; j < 300; ++j) {
70            [[Bigger alloc] init];
71        }
72        auto_collect(auto_zone(), AUTO_COLLECT_FULL_COLLECTION|AUTO_COLLECT_SYNCHRONOUS, NULL);
73        for (int j = 0; j < 300; ++j) {
74            [[NotSoSmall alloc] init];
75        }
76        auto_collect(auto_zone(), AUTO_COLLECT_FULL_COLLECTION|AUTO_COLLECT_SYNCHRONOUS, NULL);
77    }
78}
79
80int main(int argc, char *argv[]) {
81    test();
82    printf("%s: success\n", argv[0]);
83    return 0;
84}
85