Permalink
Browse files

Add minimum GC threshold option

Also rework GC option handling.

Merry xmas everybody!
  • Loading branch information...
1 parent 1e22c1c commit 9b2b65645c30756f4846a9cb275c5270402d4ca1 @nwellnhof nwellnhof committed Dec 24, 2010
View
@@ -119,12 +119,6 @@ static const struct longopt_opt_decl * Parrot_cmd_options(void);
/* HEADERIZER END: static */
-#define OPT_GC_DEBUG 128
-#define OPT_DESTROY_FLAG 129
-#define OPT_HELP_DEBUG 130
-#define OPT_PBC_OUTPUT 131
-#define OPT_RUNTIME_PREFIX 132
-
/*
=item C<static int is_all_hex_digits(const char *s)>
@@ -177,12 +171,13 @@ Parrot_cmd_options(void)
{ 'O', 'O', OPTION_optional_FLAG, { "--optimize" } },
{ 'R', 'R', OPTION_required_FLAG, { "--runcore" } },
{ 'g', 'g', OPTION_required_FLAG, { "--gc" } },
- { '\0', OPT_GC_THRESHOLD, OPTION_required_FLAG, { "--gc-threshold" } },
+ { '\0', OPT_GC_DYNAMIC_THRESHOLD, OPTION_required_FLAG, { "--gc-dynamic-threshold" } },
+ { '\0', OPT_GC_MIN_THRESHOLD, OPTION_required_FLAG, { "--gc-min-threshold" } },
+ { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
{ 'V', 'V', (OPTION_flags)0, { "--version" } },
{ 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
{ '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
{ "--leak-test", "--destroy-at-end" } },
- { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
{ 'a', 'a', (OPTION_flags)0, { "--pasm" } },
{ 'c', 'c', (OPTION_flags)0, { "--pbc" } },
{ 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } },
View
@@ -367,7 +367,8 @@ help(void)
printf(
" -w --warnings\n"
" -G --no-gc\n"
- " --gc-threshold=percentage maximum memory wasted by GC\n"
+ " --gc-dynamic-threshold=percentage maximum memory wasted by GC\n"
+ " --gc-min-threshold=KB\n"
" --gc-debug\n"
" --leak-test|--destroy-at-end\n"
" -g --gc ms|inf set GC type\n"
@@ -415,12 +416,13 @@ Parrot_cmd_options(void)
{ 'O', 'O', OPTION_optional_FLAG, { "--optimize" } },
{ 'R', 'R', OPTION_required_FLAG, { "--runcore" } },
{ 'g', 'g', OPTION_required_FLAG, { "--gc" } },
- { '\0', OPT_GC_THRESHOLD, OPTION_required_FLAG, { "--gc-threshold" } },
+ { '\0', OPT_GC_DYNAMIC_THRESHOLD, OPTION_required_FLAG, { "--gc-dynamic-threshold" } },
+ { '\0', OPT_GC_MIN_THRESHOLD, OPTION_required_FLAG, { "--gc-min-threshold" } },
+ { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
{ 'V', 'V', (OPTION_flags)0, { "--version" } },
{ 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
{ '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
{ "--leak-test", "--destroy-at-end" } },
- { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
{ 'a', 'a', (OPTION_flags)0, { "--pasm" } },
{ 'c', 'c', (OPTION_flags)0, { "--pbc" } },
{ 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } },
@@ -481,82 +483,53 @@ static void
parseflags_minimal(ARGMOD(Parrot_Init_Args * initargs), int argc, ARGIN(const char *argv[]))
{
ASSERT_ARGS(parseflags_minimal)
+ struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
+ int status;
- int pos = 0;
-
- while (pos < argc) {
- const char *arg = argv[pos];
-
- if (!strcmp(arg, "--gc")) {
- ++pos;
- if (pos == argc) {
- fprintf(stderr,
- "main: No GC specified."
- "\n\nhelp: parrot -h\n");
- exit(EXIT_FAILURE);
- }
- arg = argv[pos];
- initargs->gc_system = arg;
+ while ((status = longopt_get(argc, argv, Parrot_cmd_options(), &opt)) > 0) {
+ switch (opt.opt_id) {
+ case 'g':
+ initargs->gc_system = opt.opt_arg;
break;
- }
-
- /* arg should start with --gc-threshold *and* contain more chars */
- else if (!strncmp(arg, "--gc-threshold", 14)) {
-
- /* the next character could be '=' */
- if (arg[14] == '=') {
- arg++;
- }
+ case OPT_GC_DYNAMIC_THRESHOLD:
+ if (opt.opt_arg && is_all_digits(opt.opt_arg)) {
+ initargs->gc_dynamic_threshold = strtoul(opt.opt_arg, NULL, 10);
- /* or the end of the string... */
- else if (arg[14] == '\0'
-
- /* and there's another argument */
- && pos < argc - 1) {
- arg = argv[++pos];
+ if (initargs->gc_dynamic_threshold > 1000) {
+ fprintf(stderr, "error: maximum GC threshold is 1000\n");
+ exit(EXIT_FAILURE);
+ }
}
-
- /* ANYTHING ELSE IS WRONG */
else {
- fprintf(stderr, "--gc-threshold needs an argument");
+ fprintf(stderr, "error: invalid GC dynamic threshold specified:"
+ "'%s'\n", opt.opt_arg);
exit(EXIT_FAILURE);
}
-
- if (is_all_digits(arg)) {
- initargs->gc_threshold = strtoul(arg, NULL, 10);
-
- if (initargs->gc_threshold > 1000) {
- fprintf(stderr, "error: maximum GC threshold is 1000\n");
- exit(EXIT_FAILURE);
- }
+ break;
+ case OPT_GC_MIN_THRESHOLD:
+ if (opt.opt_arg && is_all_digits(opt.opt_arg)) {
+ initargs->gc_min_threshold = strtoul(opt.opt_arg, NULL, 10)
+ * 1024;
}
else {
- fprintf(stderr, "error: invalid GC threshold specified:"
- "'%s'\n", arg);
+ fprintf(stderr, "error: invalid GC min threshold specified:"
+ "'%s'\n", opt.opt_arg);
exit(EXIT_FAILURE);
}
- ++pos;
- arg = argv[pos];
- }
- else if (!strncmp(arg, "--hash-seed", 11)) {
-
- if ((arg = strrchr(arg, '=')))
- ++arg;
- else
- arg = argv[++pos];
-
- if (is_all_hex_digits(arg)) {
- initargs->hash_seed = strtoul(arg, NULL, 16);
+ break;
+ case OPT_HASH_SEED:
+ if (opt.opt_arg && is_all_hex_digits(opt.opt_arg)) {
+ initargs->hash_seed = strtoul(opt.opt_arg, NULL, 16);
}
else {
fprintf(stderr, "error: invalid hash seed specified:"
- "'%s'\n", arg);
+ "'%s'\n", opt.opt_arg);
exit(EXIT_FAILURE);
}
- ++pos;
- arg = argv[pos];
+ break;
+ default:
+ break;
}
- ++pos;
}
}
@@ -595,11 +568,10 @@ parseflags(Parrot_PMC interp,
*core = opt.opt_arg;
break;
case 'g':
+ case OPT_GC_DYNAMIC_THRESHOLD:
+ case OPT_GC_MIN_THRESHOLD:
/* Handled in parseflags_minimal */
break;
- case OPT_GC_THRESHOLD:
- /* handled in parseflags_minimal */
- break;
case 't':
if (opt.opt_arg && is_all_hex_digits(opt.opt_arg)) {
const unsigned long _temp = strtoul(opt.opt_arg, NULL, 16);
View
@@ -49,8 +49,9 @@ typedef int (*imcc_hack_func_t)(Parrot_PMC, const char *, int, const char **, Pa
typedef struct _Parrot_Init_Args {
void *stacktop;
- const char * gc_system;
- Parrot_Int gc_threshold;
+ const char *gc_system;
+ Parrot_Int gc_dynamic_threshold;
+ Parrot_Int gc_min_threshold;
Parrot_UInt hash_seed;
} Parrot_Init_Args;
@@ -170,8 +171,9 @@ PARROT_API
Parrot_Int Parrot_api_make_interpreter(
Parrot_PMC parent,
Parrot_Int flags,
- ARGIN_NULLOK(Parrot_Init_Args *args),
+ ARGIN(Parrot_Init_Args *args),
ARGOUT(Parrot_PMC *interp))
+ __attribute__nonnull__(3)
__attribute__nonnull__(4)
FUNC_MODIFIES(*interp);
@@ -274,7 +276,8 @@ Parrot_Int Parrot_api_wrap_imcc_hack(
, PARROT_ASSERT_ARG(pbc))
#define ASSERT_ARGS_Parrot_api_load_language __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_api_make_interpreter __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
+ PARROT_ASSERT_ARG(args) \
+ , PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_api_ready_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(main_sub))
#define ASSERT_ARGS_Parrot_api_run_bytecode __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
View
@@ -31,7 +31,12 @@
#define ALIGNED_STRING_SIZE(len) (((len) + sizeof (void*) + WORD_ALIGN_1) & WORD_ALIGN_MASK)
-#define GC_DYNAMIC_THRESHOLD_DEFAULT 75
+typedef struct _Parrot_GC_Init_Args {
+ void *stacktop;
+ const char *system;
+ Parrot_Int dynamic_threshold;
+ Parrot_Int min_threshold;
+} Parrot_GC_Init_Args;
typedef enum _gc_sys_type_enum {
MS, /* mark and sweep */
@@ -167,10 +172,6 @@ void * Parrot_gc_reallocate_memory_chunk_with_interior_pointers(PARROT_INTERP,
__attribute__nonnull__(1);
PARROT_EXPORT
-void Parrot_gc_set_system_type(PARROT_INTERP, const char *name)
- __attribute__nonnull__(1);
-
-PARROT_EXPORT
unsigned int Parrot_is_blocked_GC_mark(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -276,7 +277,7 @@ size_t Parrot_gc_headers_alloc_since_last_collect(PARROT_INTERP)
UINTVAL Parrot_gc_impatient_pmcs(PARROT_INTERP)
__attribute__nonnull__(1);
-void Parrot_gc_initialize(PARROT_INTERP, ARGIN(void *stacktop))
+void Parrot_gc_initialize(PARROT_INTERP, ARGIN(Parrot_GC_Init_Args *args))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -362,8 +363,6 @@ int Parrot_gc_total_sized_buffers(PARROT_INTERP)
#define ASSERT_ARGS_Parrot_gc_reallocate_memory_chunk_with_interior_pointers \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_Parrot_gc_set_system_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_is_blocked_GC_mark __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_is_blocked_GC_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -433,7 +432,7 @@ int Parrot_gc_total_sized_buffers(PARROT_INTERP)
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_gc_initialize __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(stacktop))
+ , PARROT_ASSERT_ARG(args))
#define ASSERT_ARGS_Parrot_gc_mark_and_sweep __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_gc_mem_alloc_since_last_collect \
@@ -129,6 +129,7 @@ typedef Parrot_Run_core_t Run_Cores;
#include "parrot/debugger.h"
#include "parrot/multidispatch.h"
#include "parrot/call.h"
+#include "parrot/gc_api.h"
typedef struct warnings_t {
Warnings_classes classes;
@@ -170,8 +171,6 @@ struct parrot_interp_t {
struct GC_Subsystem *gc_sys; /* functions and data specific
to current GC subsystem*/
- UINTVAL gc_threshold; /* maximum percentage of memory
- wasted by GC */
PMC *gc_registry; /* root set of registered PMCs */
@@ -361,7 +360,8 @@ Parrot_Interp allocate_interpreter(
PARROT_EXPORT
PARROT_CANNOT_RETURN_NULL
-Parrot_Interp initialize_interpreter(PARROT_INTERP, ARGIN(void *stacktop))
+Parrot_Interp initialize_interpreter(PARROT_INTERP,
+ ARGIN(Parrot_GC_Init_Args *args))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
@@ -382,7 +382,7 @@ void Parrot_really_destroy(PARROT_INTERP,
#define ASSERT_ARGS_allocate_interpreter __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_initialize_interpreter __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(stacktop))
+ , PARROT_ASSERT_ARG(args))
#define ASSERT_ARGS_make_interpreter __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_Parrot_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
View
@@ -40,13 +40,14 @@ struct longopt_opt_info {
#define LONGOPT_OPT_INFO_INIT { 1, 0, NULL, NULL, NULL }
-#define OPT_GC_DEBUG 128
-#define OPT_DESTROY_FLAG 129
-#define OPT_HELP_DEBUG 130
-#define OPT_PBC_OUTPUT 131
-#define OPT_RUNTIME_PREFIX 132
-#define OPT_HASH_SEED 133
-#define OPT_GC_THRESHOLD 134
+#define OPT_GC_DEBUG 128
+#define OPT_DESTROY_FLAG 129
+#define OPT_HELP_DEBUG 130
+#define OPT_PBC_OUTPUT 131
+#define OPT_RUNTIME_PREFIX 132
+#define OPT_HASH_SEED 133
+#define OPT_GC_DYNAMIC_THRESHOLD 134
+#define OPT_GC_MIN_THRESHOLD 135
/* HEADERIZER BEGIN: src/longopt.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
View
@@ -147,9 +147,8 @@ PMC * Parrot_pmc_reuse_init(PARROT_INTERP,
PARROT_HOT
PARROT_INLINE
-PMC * Parrot_pmc_box_string(PARROT_INTERP, ARGIN(STRING *string))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
+PMC * Parrot_pmc_box_string(PARROT_INTERP, ARGIN_NULLOK(STRING *string))
+ __attribute__nonnull__(1);
void Parrot_pmc_free_temporary(PARROT_INTERP, ARGMOD(PMC *pmc))
__attribute__nonnull__(1)
View
@@ -116,25 +116,22 @@ is successful and false value otherwise.
PARROT_API
Parrot_Int
Parrot_api_make_interpreter(Parrot_PMC parent, Parrot_Int flags,
- ARGIN_NULLOK(Parrot_Init_Args *args), ARGOUT(Parrot_PMC *interp))
+ ARGIN(Parrot_Init_Args *args), ARGOUT(Parrot_PMC *interp))
{
ASSERT_ARGS(Parrot_api_make_interpreter)
int alt_stacktop;
Parrot_Interp interp_raw;
+ Parrot_GC_Init_Args gc_args;
void *stacktop_ptr = &alt_stacktop;
const Parrot_Interp parent_raw = PMC_IS_NULL(parent) ? NULL : GET_RAW_INTERP(parent);
interp_raw = allocate_interpreter(parent_raw, flags);
- if (args) {
- if (args->stacktop)
- stacktop_ptr = args->stacktop;
- if (args->gc_system)
- Parrot_gc_set_system_type(interp_raw, args->gc_system);
- if (args->gc_threshold)
- interp_raw->gc_threshold = args->gc_threshold;
- if (args->hash_seed)
- interp_raw->hash_seed = args->hash_seed;
- }
- initialize_interpreter(interp_raw, stacktop_ptr);
+ if (args->hash_seed)
+ interp_raw->hash_seed = args->hash_seed;
+ gc_args.stacktop = args->stacktop ? args->stacktop : &alt_stacktop;
+ gc_args.system = args->gc_system;
+ gc_args.dynamic_threshold = args->gc_dynamic_threshold;
+ gc_args.min_threshold = args->gc_min_threshold;
+ initialize_interpreter(interp_raw, &gc_args);
*interp = VTABLE_get_pmc_keyed_int(
interp_raw, interp_raw->iglobals, (Parrot_Int)IGLOBALS_INTERPRETER);
return !PMC_IS_NULL(*interp);
Oops, something went wrong.

0 comments on commit 9b2b656

Please sign in to comment.