<commit_before>/** 
 * Cyclone Scheme
 * Copyright (c) 2014, <NAME>
 * All rights reserved.
 *
 * This file contains C types used by compiled programs.
 */

#ifndef CYCLONE_TYPES_H
#define CYCLONE_TYPES_H

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <setjmp.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <pthread.h>

// Maximum number of args that GC will accept
#define NUM_GC_ANS 128

// Which way does the CPU grow its stack?
#define STACK_GROWS_DOWNWARD 1

// Size of the stack buffer, in bytes.
// This is used as the first generation of the GC.
#define STACK_SIZE 250000

// Size of a "page" on the heap (the second generation), in bytes.
#define HEAP_SIZE 6000000

/* Define general object type. */
typedef void *object;

/* Thread data structures */
typedef struct gc_thread_data_t gc_thread_data;
struct gc_thread_data_t {
  // Data needed to initiate stack-based minor GC
  char *stack_start;
  char *stack_limit;
//TODO: store stack traces per thread
  // List of objects moved to heap during minor GC
  void **moveBuf;
  int moveBufLen;
  // Need the following to perform longjmp's
  //int mutator_num;
  jmp_buf *jmp_start;
  // After longjmp, pick up execution using continuation/arguments
  object gc_cont;
  object *gc_args;
  short gc_num_args;
  // Data needed for heap GC
  int gc_alloc_color;
  int gc_status;
  int last_write;
  int last_read;
  void **mark_buffer;
  int mark_buffer_len;
  pthread_mutex_t lock;
};

/* GC data structures */

typedef struct gc_free_list_t gc_free_list;
struct gc_free_list_t {
//  somehow this size param is being overwritten by a "mark() =".
//  how could that happen?
somehow it appears free list pointers are being used where heap objects are
expected. could this be as simple as objects being sweeped that should not
have been? unfortunately it is harder to figure how why the objects were 
sweeped. were they not marked properly? is there a race condition? maybe
more than one issue? what is going on?
unsigned int dummy; // just for testing/evaluation, this line is NOT a fix!!
  unsigned int size;
  gc_free_list *next;
};

typedef struct gc_heap_t gc_heap;
struct gc_heap_t {
  unsigned int size;
  unsigned int chunk_size; // 0 for any size, other and heap will only alloc chunks of that size
  unsigned int max_size;
  gc_free_list *free_list; // TBD
  gc_heap *next; // TBD, linked list is not very efficient, but easy to work with as a start
  char *data;
};

typedef struct gc_header_type_t gc_header_type;
struct gc_header_type_t {
  //unsigned char mark; // mark bits (only need 2)
  unsigned int mark; // mark bits (only need 2)
  // TODO: forwarding address (probably not needed for mark/sweep), anything else???
};
#define mark(x) (((list) x)->hdr.mark)

/* HEAP definitions */
// experimenting with a heap based off of the one in Chibi scheme<commit_msg>notes<commit_after>/** 
 * Cyclone Scheme
 * Copyright (c) 2014, <NAME>
 * All rights reserved.
 *
 * This file contains C types used by compiled programs.
 */

#ifndef CYCLONE_TYPES_H
#define CYCLONE_TYPES_H

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <setjmp.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <pthread.h>

// Maximum number of args that GC will accept
#define NUM_GC_ANS 128

// Which way does the CPU grow its stack?
#define STACK_GROWS_DOWNWARD 1

// Size of the stack buffer, in bytes.
// This is used as the first generation of the GC.
#define STACK_SIZE 250000

// Size of a "page" on the heap (the second generation), in bytes.
#define HEAP_SIZE 6000000

/* Define general object type. */
typedef void *object;

/* Thread data structures */
typedef struct gc_thread_data_t gc_thread_data;
struct gc_thread_data_t {
  // Data needed to initiate stack-based minor GC
  char *stack_start;
  char *stack_limit;
//TODO: store stack traces per thread
  // List of objects moved to heap during minor GC
  void **moveBuf;
  int moveBufLen;
  // Need the following to perform longjmp's
  //int mutator_num;
  jmp_buf *jmp_start;
  // After longjmp, pick up execution using continuation/arguments
  object gc_cont;
  object *gc_args;
  short gc_num_args;
  // Data needed for heap GC
  int gc_alloc_color;
  int gc_status;
  int last_write;
  int last_read;
  void **mark_buffer;
  int mark_buffer_len;
  pthread_mutex_t lock;
};

/* GC data structures */

typedef struct gc_free_list_t gc_free_list;
struct gc_free_list_t {
//  somehow this size param is being overwritten by a "mark() =".
//  how could that happen?
//somehow it appears free list pointers are being used where heap objects are
//expected. could this be as simple as objects being sweeped that should not
//have been? unfortunately it is harder to figure how why the objects were 
//sweeped. were they not marked properly? is there a race condition? maybe
//more than one issue? what is going on?
//
// the following line does not solve the problem. in fact, with this in
// place there are still cases where the tag is a multiple of 32, implying
// again that a free list node is being used as a heap object. IE, the
// size value is being read into the tag field by code expecting a heap obj.
//
//unsigned int dummy; // just for testing/evaluation, this line is NOT a fix!!
  unsigned int size;
  gc_free_list *next;
};

typedef struct gc_heap_t gc_heap;
struct gc_heap_t {
  unsigned int size;
  unsigned int chunk_size; // 0 for any size, other and heap will only alloc chunks of that size
  unsigned int max_size;
  gc_free_list *free_list; // TBD
  gc_heap *next; // TBD, linked list is not very efficient, but easy to work with as a start
  char *data;
};

typedef struct gc_header_type_t gc_header_type;
struct gc_header_type_t {
  //unsigned char mark; // mark bits (only need 2)
  unsigned int mark; // mark bits (only need 2)
  // TODO: forwarding address (probably not needed for mark/sweep), anything else???
};
#define mark(x) (((list) x)->hdr.mark)

/* HEAP definitions */
// experimenting with a heap based off of the one in Chibi scheme
{'fraction_non_alphanumeric': 0.08359491161407566, 'fraction_numerical': 0.008260366760284157, 'mean_word_length': 3.748235294117647, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1037404', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1911, 'n_words': 824}