added hawk::gc(), hawk::gc_set_threshold(), hawk::gc_get_threshold()

This commit is contained in:
hyung-hwan 2020-03-28 08:04:37 +00:00
parent 7d70005984
commit a93beaaf55
10 changed files with 330 additions and 33 deletions

View File

@ -185,6 +185,7 @@ if ENABLE_STATIC_MODULE
# STATIC MODULES BUILT INTO MAIN LIBRARY
##################################################
libhawk_la_SOURCES += \
mod-hawk.c mod-hawk.h \
mod-math.c mod-math.h \
mod-str.c mod-str.h \
mod-sys.c mod-sys.h
@ -213,6 +214,13 @@ DEPENDENCIES_MOD_COMMON = libhawk.la
#pkglibdir = $(libdir)
#pkglib_LTLIBRARIES =
pkglib_LTLIBRARIES += libhawk-hawk.la
libhawk_hawk_la_SOURCES = mod-hawk.c mod-hawk.h
libhawk_hawk_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON)
libhawk_hawk_la_LDFLAGS = $(LDFLAGS_MOD_COMMON)
libhawk_hawk_la_LIBADD = $(LIBADD_MOD_COMMON)
libhawk_hawk_la_DEPENDENCIES = $(DEPENDENCIES_MOD_COMMON)
pkglib_LTLIBRARIES += libhawk-math.la
libhawk_math_la_SOURCES = mod-math.c mod-math.h
libhawk_math_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON)

View File

@ -100,6 +100,7 @@ host_triplet = @host@
# STATIC MODULES BUILT INTO MAIN LIBRARY
##################################################
@ENABLE_STATIC_MODULE_TRUE@am__append_9 = \
@ENABLE_STATIC_MODULE_TRUE@ mod-hawk.c mod-hawk.h \
@ENABLE_STATIC_MODULE_TRUE@ mod-math.c mod-math.h \
@ENABLE_STATIC_MODULE_TRUE@ mod-str.c mod-str.h \
@ENABLE_STATIC_MODULE_TRUE@ mod-sys.c mod-sys.h
@ -112,8 +113,9 @@ host_triplet = @host@
#pkglibdir = $(libdir)
#pkglib_LTLIBRARIES =
@ENABLE_STATIC_MODULE_FALSE@am__append_15 = libhawk-math.la \
@ENABLE_STATIC_MODULE_FALSE@ libhawk-str.la libhawk-sys.la
@ENABLE_STATIC_MODULE_FALSE@am__append_15 = libhawk-hawk.la \
@ENABLE_STATIC_MODULE_FALSE@ libhawk-math.la libhawk-str.la \
@ENABLE_STATIC_MODULE_FALSE@ libhawk-sys.la
subdir = lib
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
@ -163,14 +165,24 @@ am__installdirs = "$(DESTDIR)$(pkglibdir)" \
"$(DESTDIR)$(pkgincludedir)"
LTLIBRARIES = $(pkglib_LTLIBRARIES)
am__DEPENDENCIES_1 =
am__libhawk_math_la_SOURCES_DIST = mod-math.c mod-math.h
@ENABLE_STATIC_MODULE_FALSE@am_libhawk_math_la_OBJECTS = \
@ENABLE_STATIC_MODULE_FALSE@ libhawk_math_la-mod-math.lo
libhawk_math_la_OBJECTS = $(am_libhawk_math_la_OBJECTS)
am__libhawk_hawk_la_SOURCES_DIST = mod-hawk.c mod-hawk.h
@ENABLE_STATIC_MODULE_FALSE@am_libhawk_hawk_la_OBJECTS = \
@ENABLE_STATIC_MODULE_FALSE@ libhawk_hawk_la-mod-hawk.lo
libhawk_hawk_la_OBJECTS = $(am_libhawk_hawk_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
libhawk_hawk_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(AM_CFLAGS) $(CFLAGS) $(libhawk_hawk_la_LDFLAGS) $(LDFLAGS) \
-o $@
@ENABLE_STATIC_MODULE_FALSE@am_libhawk_hawk_la_rpath = -rpath \
@ENABLE_STATIC_MODULE_FALSE@ $(pkglibdir)
am__libhawk_math_la_SOURCES_DIST = mod-math.c mod-math.h
@ENABLE_STATIC_MODULE_FALSE@am_libhawk_math_la_OBJECTS = \
@ENABLE_STATIC_MODULE_FALSE@ libhawk_math_la-mod-math.lo
libhawk_math_la_OBJECTS = $(am_libhawk_math_la_OBJECTS)
libhawk_math_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(AM_CFLAGS) $(CFLAGS) $(libhawk_math_la_LDFLAGS) $(LDFLAGS) \
@ -216,13 +228,14 @@ am__libhawk_la_SOURCES_DIST = hawk.h hawk-arr.h hawk-chr.h hawk-cmn.h \
utl-str.c utl-sys.c utl.c val-prv.h val.c hawk-cli.h \
hawk-fio.h hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h \
cli-imp.h cli.c fio.c mtx.c pio.c sio.c syscall.h tio.c \
std-prv.h std.c Hawk.cpp HawkStd.cpp mod-math.c mod-math.h \
mod-str.c mod-str.h mod-sys.c mod-sys.h
std-prv.h std.c Hawk.cpp HawkStd.cpp mod-hawk.c mod-hawk.h \
mod-math.c mod-math.h mod-str.c mod-str.h mod-sys.c mod-sys.h
am__objects_1 =
am__objects_2 = $(am__objects_1)
@ENABLE_CXX_TRUE@am__objects_3 = libhawk_la-Hawk.lo \
@ENABLE_CXX_TRUE@ libhawk_la-HawkStd.lo
@ENABLE_STATIC_MODULE_TRUE@am__objects_4 = libhawk_la-mod-math.lo \
@ENABLE_STATIC_MODULE_TRUE@am__objects_4 = libhawk_la-mod-hawk.lo \
@ENABLE_STATIC_MODULE_TRUE@ libhawk_la-mod-math.lo \
@ENABLE_STATIC_MODULE_TRUE@ libhawk_la-mod-str.lo \
@ENABLE_STATIC_MODULE_TRUE@ libhawk_la-mod-sys.lo
am_libhawk_la_OBJECTS = $(am__objects_2) libhawk_la-arr.lo \
@ -260,7 +273,8 @@ am__v_at_1 =
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/libhawk_la-Hawk.Plo \
am__depfiles_remade = ./$(DEPDIR)/libhawk_hawk_la-mod-hawk.Plo \
./$(DEPDIR)/libhawk_la-Hawk.Plo \
./$(DEPDIR)/libhawk_la-HawkStd.Plo \
./$(DEPDIR)/libhawk_la-arr.Plo ./$(DEPDIR)/libhawk_la-chr.Plo \
./$(DEPDIR)/libhawk_la-cli.Plo ./$(DEPDIR)/libhawk_la-dir.Plo \
@ -274,6 +288,7 @@ am__depfiles_remade = ./$(DEPDIR)/libhawk_la-Hawk.Plo \
./$(DEPDIR)/libhawk_la-gem.Plo ./$(DEPDIR)/libhawk_la-hawk.Plo \
./$(DEPDIR)/libhawk_la-htb.Plo ./$(DEPDIR)/libhawk_la-mb8.Plo \
./$(DEPDIR)/libhawk_la-misc.Plo \
./$(DEPDIR)/libhawk_la-mod-hawk.Plo \
./$(DEPDIR)/libhawk_la-mod-math.Plo \
./$(DEPDIR)/libhawk_la-mod-str.Plo \
./$(DEPDIR)/libhawk_la-mod-sys.Plo \
@ -339,9 +354,11 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
am__v_CXXLD_0 = @echo " CXXLD " $@;
am__v_CXXLD_1 =
SOURCES = $(libhawk_math_la_SOURCES) $(libhawk_str_la_SOURCES) \
$(libhawk_sys_la_SOURCES) $(libhawk_la_SOURCES)
DIST_SOURCES = $(am__libhawk_math_la_SOURCES_DIST) \
SOURCES = $(libhawk_hawk_la_SOURCES) $(libhawk_math_la_SOURCES) \
$(libhawk_str_la_SOURCES) $(libhawk_sys_la_SOURCES) \
$(libhawk_la_SOURCES)
DIST_SOURCES = $(am__libhawk_hawk_la_SOURCES_DIST) \
$(am__libhawk_math_la_SOURCES_DIST) \
$(am__libhawk_str_la_SOURCES_DIST) \
$(am__libhawk_sys_la_SOURCES_DIST) \
$(am__libhawk_la_SOURCES_DIST)
@ -610,6 +627,11 @@ libhawk_la_DEPENDENCIES = $(am__append_12) $(am__append_14)
@ENABLE_STATIC_MODULE_FALSE@LDFLAGS_MOD_COMMON = $(LDFLAGS_ALL_COMMON)
@ENABLE_STATIC_MODULE_FALSE@LIBADD_MOD_COMMON = -lhawk
@ENABLE_STATIC_MODULE_FALSE@DEPENDENCIES_MOD_COMMON = libhawk.la
@ENABLE_STATIC_MODULE_FALSE@libhawk_hawk_la_SOURCES = mod-hawk.c mod-hawk.h
@ENABLE_STATIC_MODULE_FALSE@libhawk_hawk_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_hawk_la_LDFLAGS = $(LDFLAGS_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_hawk_la_LIBADD = $(LIBADD_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_hawk_la_DEPENDENCIES = $(DEPENDENCIES_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_math_la_SOURCES = mod-math.c mod-math.h
@ENABLE_STATIC_MODULE_FALSE@libhawk_math_la_CPPFLAGS = $(CPPFLAGS_MOD_COMMON)
@ENABLE_STATIC_MODULE_FALSE@libhawk_math_la_LDFLAGS = $(LDFLAGS_MOD_COMMON)
@ -710,6 +732,9 @@ clean-pkglibLTLIBRARIES:
rm -f $${locs}; \
}
libhawk-hawk.la: $(libhawk_hawk_la_OBJECTS) $(libhawk_hawk_la_DEPENDENCIES) $(EXTRA_libhawk_hawk_la_DEPENDENCIES)
$(AM_V_CCLD)$(libhawk_hawk_la_LINK) $(am_libhawk_hawk_la_rpath) $(libhawk_hawk_la_OBJECTS) $(libhawk_hawk_la_LIBADD) $(LIBS)
libhawk-math.la: $(libhawk_math_la_OBJECTS) $(libhawk_math_la_DEPENDENCIES) $(EXTRA_libhawk_math_la_DEPENDENCIES)
$(AM_V_CCLD)$(libhawk_math_la_LINK) $(am_libhawk_math_la_rpath) $(libhawk_math_la_OBJECTS) $(libhawk_math_la_LIBADD) $(LIBS)
@ -728,6 +753,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_hawk_la-mod-hawk.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-Hawk.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-HawkStd.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-arr.Plo@am__quote@ # am--include-marker
@ -748,6 +774,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-htb.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mb8.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-misc.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-hawk.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-math.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-str.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-mod-sys.Plo@am__quote@ # am--include-marker
@ -813,6 +840,13 @@ am--depfiles: $(am__depfiles_remade)
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
libhawk_hawk_la-mod-hawk.lo: mod-hawk.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_hawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_hawk_la-mod-hawk.lo -MD -MP -MF $(DEPDIR)/libhawk_hawk_la-mod-hawk.Tpo -c -o libhawk_hawk_la-mod-hawk.lo `test -f 'mod-hawk.c' || echo '$(srcdir)/'`mod-hawk.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_hawk_la-mod-hawk.Tpo $(DEPDIR)/libhawk_hawk_la-mod-hawk.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mod-hawk.c' object='libhawk_hawk_la-mod-hawk.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_hawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_hawk_la-mod-hawk.lo `test -f 'mod-hawk.c' || echo '$(srcdir)/'`mod-hawk.c
libhawk_math_la-mod-math.lo: mod-math.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_math_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_math_la-mod-math.lo -MD -MP -MF $(DEPDIR)/libhawk_math_la-mod-math.Tpo -c -o libhawk_math_la-mod-math.lo `test -f 'mod-math.c' || echo '$(srcdir)/'`mod-math.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_math_la-mod-math.Tpo $(DEPDIR)/libhawk_math_la-mod-math.Plo
@ -1156,6 +1190,13 @@ libhawk_la-std.lo: std.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-std.lo `test -f 'std.c' || echo '$(srcdir)/'`std.c
libhawk_la-mod-hawk.lo: mod-hawk.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-mod-hawk.lo -MD -MP -MF $(DEPDIR)/libhawk_la-mod-hawk.Tpo -c -o libhawk_la-mod-hawk.lo `test -f 'mod-hawk.c' || echo '$(srcdir)/'`mod-hawk.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-mod-hawk.Tpo $(DEPDIR)/libhawk_la-mod-hawk.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mod-hawk.c' object='libhawk_la-mod-hawk.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-mod-hawk.lo `test -f 'mod-hawk.c' || echo '$(srcdir)/'`mod-hawk.c
libhawk_la-mod-math.lo: mod-math.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-mod-math.lo -MD -MP -MF $(DEPDIR)/libhawk_la-mod-math.Tpo -c -o libhawk_la-mod-math.lo `test -f 'mod-math.c' || echo '$(srcdir)/'`mod-math.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-mod-math.Tpo $(DEPDIR)/libhawk_la-mod-math.Plo
@ -1370,7 +1411,8 @@ clean-am: clean-generic clean-libtool clean-pkglibLTLIBRARIES \
mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/libhawk_la-Hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_hawk_la-mod-hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_la-Hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_la-HawkStd.Plo
-rm -f ./$(DEPDIR)/libhawk_la-arr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-chr.Plo
@ -1390,6 +1432,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/libhawk_la-htb.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mb8.Plo
-rm -f ./$(DEPDIR)/libhawk_la-misc.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-math.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-str.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-sys.Plo
@ -1470,7 +1513,8 @@ install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhawk_la-Hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_hawk_la-mod-hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_la-Hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_la-HawkStd.Plo
-rm -f ./$(DEPDIR)/libhawk_la-arr.Plo
-rm -f ./$(DEPDIR)/libhawk_la-chr.Plo
@ -1490,6 +1534,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libhawk_la-htb.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mb8.Plo
-rm -f ./$(DEPDIR)/libhawk_la-misc.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-hawk.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-math.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-str.Plo
-rm -f ./$(DEPDIR)/libhawk_la-mod-sys.Plo

View File

@ -409,10 +409,11 @@ struct hawk_rtx_t
hawk_gch_t g[HAWK_GC_NUM_GENS];
/*
* ncolls[0] - number of allocation attempt since the last gc
* ncolls[N] - nubmer of collections performed for generation N - 1.
* Pressure imposed on each generation before gc is triggered
* pressure[0] - number of allocation attempt since the last gc
* pressure[N] - nubmer of collections performed for generation N - 1.
*/
hawk_oow_t ncolls[HAWK_GC_NUM_GENS + 1];
hawk_oow_t pressure[HAWK_GC_NUM_GENS + 1];
/* threshold to trigger generational collection. */
hawk_oow_t threshold[HAWK_GC_NUM_GENS];

View File

@ -3007,7 +3007,12 @@ HAWK_EXPORT void hawk_rtx_refdownval_nofree (
#define HAWK_RTX_GC_GEN_FULL (HAWK_TYPE_MAX(int))
#define HAWK_RTX_GC_GEN_AUTO (-1)
HAWK_EXPORT void hawk_rtx_gc (
/*
* The hawk_rtc_gc() function triggers garbage collection.
* It returns the generation number collected and never fails
*/
HAWK_EXPORT int hawk_rtx_gc (
hawk_rtx_t* rtx,
int gen
);

192
hawk/lib/mod-hawk.c Normal file
View File

@ -0,0 +1,192 @@
/*
* $Id$
*
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "mod-hawk.h"
#include "hawk-prv.h"
/*
hawk::gc();
hawk::gc_set_threshold(gen)
hawk::gc_get_threshold(gen)
hawk::GC_NUM_GENS
*/
static int fnc_gc (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_int_t gen = -1;
if (hawk_rtx_getnargs(rtx) >= 1 && hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 0), &gen) <= -1) gen = -1;
gen = hawk_rtx_gc(rtx, gen);
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(gen));
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, gen));
return 0;
}
static int fnc_gc_get_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_int_t gen;
hawk_int_t threshold;
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 0), &gen) <= -1) gen = 0;
if (gen < 0) gen = 0;
else if (gen >= HAWK_COUNTOF(rtx->gc.g)) gen = HAWK_COUNTOF(rtx->gc.g) - 1;
threshold = rtx->gc.threshold[gen];
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(threshold));
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, threshold));
return 0;
}
static int fnc_gc_set_threshold (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_int_t gen;
hawk_int_t threshold;
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 0), &gen) <= -1) gen = 0;
if (gen < 0) gen = 0;
else if (gen >= HAWK_COUNTOF(rtx->gc.g)) gen = HAWK_COUNTOF(rtx->gc.g) - 1;
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 1), &threshold) <= -1) threshold = -1;
if (threshold >= 0)
{
if (threshold >= HAWK_QUICKINT_MAX) threshold = HAWK_QUICKINT_MAX;
rtx->gc.threshold[gen] = threshold; /* update */
}
else
{
threshold = rtx->gc.threshold[gen]; /* no update. but retrieve the existing value */
}
HAWK_ASSERT (HAWK_IN_QUICKINT_RANGE(threshold));
hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, threshold));
return 0;
}
typedef struct fnctab_t fnctab_t;
struct fnctab_t
{
const hawk_ooch_t* name;
hawk_mod_sym_fnc_t info;
};
typedef struct inttab_t inttab_t;
struct inttab_t
{
const hawk_ooch_t* name;
hawk_mod_sym_int_t info;
};
#define A_MAX HAWK_TYPE_MAX(int)
static fnctab_t fnctab[] =
{
/* keep this table sorted for binary search in query(). */
{ HAWK_T("gc"), { { 0, 1, HAWK_NULL }, fnc_gc, 0 } },
{ HAWK_T("gc_get_threshold"), { { 1, 1, HAWK_NULL }, fnc_gc_get_threshold, 0 } },
{ HAWK_T("gc_set_threshold"), { { 2, 2, HAWK_NULL }, fnc_gc_set_threshold, 0 } }
};
static inttab_t inttab[] =
{
/* keep this table sorted for binary search in query(). */
{ HAWK_T("GC_NUM_GENS"), { HAWK_GC_NUM_GENS } }
};
static int query (hawk_mod_t* mod, hawk_t* awk, const hawk_ooch_t* name, hawk_mod_sym_t* sym)
{
int left, right, mid, n;
left = 0; right = HAWK_COUNTOF(fnctab) - 1;
while (left <= right)
{
mid = left + (right - left) / 2;
n = hawk_comp_oocstr(fnctab[mid].name, name, 0);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{
sym->type = HAWK_MOD_FNC;
sym->u.fnc = fnctab[mid].info;
return 0;
}
}
left = 0; right = HAWK_COUNTOF(inttab) - 1;
while (left <= right)
{
mid = left + (right - left) / 2;
n = hawk_comp_oocstr(inttab[mid].name, name, 0);
if (n > 0) right = mid - 1;
else if (n < 0) left = mid + 1;
else
{
sym->type = HAWK_MOD_INT;
sym->u.in = inttab[mid].info;
return 0;
}
}
hawk_seterrfmt (awk, HAWK_NULL, HAWK_ENOENT, HAWK_T("'%js' not found"), name);
return -1;
}
/* TODO: proper resource management */
static int init (hawk_mod_t* mod, hawk_rtx_t* rtx)
{
return 0;
}
static void fini (hawk_mod_t* mod, hawk_rtx_t* rtx)
{
/* TODO: anything */
}
static void unload (hawk_mod_t* mod, hawk_t* awk)
{
/* TODO: anything */
}
int hawk_mod_hawk (hawk_mod_t* mod, hawk_t* awk)
{
mod->query = query;
mod->unload = unload;
mod->init = init;
mod->fini = fini;
/*
mod->ctx...
*/
return 0;
}

43
hawk/lib/mod-hawk.h Normal file
View File

@ -0,0 +1,43 @@
/*
* $Id$
*
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _HAWK_MOD_HAWK_H_
#define _HAWK_MOD_HAWK_H_
#include <hawk.h>
#if defined(__cplusplus)
extern "C" {
#endif
HAWK_EXPORT int hawk_mod_hawk (hawk_mod_t* mod, hawk_t* awk);
#if defined(__cplusplus)
}
#endif
#endif

View File

@ -626,7 +626,7 @@ static int query (hawk_mod_t* mod, hawk_t* awk, const hawk_ooch_t* name, hawk_mo
sym->u.in = inttab[mid].info;
return 0;
}
}
}
hawk_seterrfmt (awk, HAWK_NULL, HAWK_ENOENT, HAWK_T("'%js' not found"), name);
return -1;

View File

@ -7185,6 +7185,7 @@ int hawk_putsrcoochars (hawk_t* hawk, const hawk_ooch_t* str, hawk_oow_t len)
#if defined(HAWK_ENABLE_STATIC_MODULE)
/* let's hardcode module information */
#include "mod-hawk.h"
#include "mod-math.h"
#include "mod-str.h"
#include "mod-sys.h"
@ -7209,6 +7210,7 @@ static struct
int (*modload) (hawk_mod_t* mod, hawk_t* awk);
} static_modtab[] =
{
{ HAWK_T("hawk"), hawk_mod_hawk },
{ HAWK_T("math"), hawk_mod_math },
#if defined(HAWK_ENABLE_MOD_MYSQL)
{ HAWK_T("mysql"), hawk_mod_mysql },

View File

@ -1039,12 +1039,12 @@ static int init_rtx (hawk_rtx_t* rtx, hawk_t* awk, hawk_rio_cbs_t* rio)
rtx->gc.g[i].gc_prev = &rtx->gc.g[i];
/* initialize some counters */
rtx->gc.ncolls[i] = 0;
rtx->gc.threshold[i] = (HAWK_COUNTOF(rtx->gc.g) - i) * 3;
rtx->gc.pressure[i] = 0;
rtx->gc.threshold[i] = (HAWK_COUNTOF(rtx->gc.g) - i) * 10;
if (i == 0 && rtx->gc.threshold[i] < 100) rtx->gc.threshold[i] = 100; /* minimum threshold for gen 0 is 100 */
}
rtx->gc.ncolls[i] = 0; /* ncolls is larger than other elements by 1 in size */
rtx->gc.pressure[i] = 0; /* pressure is larger than other elements by 1 in size */
rtx->inrec.buf_pos = 0;
rtx->inrec.buf_len = 0;

View File

@ -335,12 +335,12 @@ static HAWK_INLINE void gc_collect_garbage_in_generation (hawk_rtx_t* rtx, int g
gc_move_all_gchs (&reachable, &rtx->gc.g[newgen]);
}
/* [NOTE] ncolls is greater than other elements by 1 in size.
* i store the number of collections for gen 0 in ncolls[1].
/* [NOTE] pressure is greater than other elements by 1 in size.
* i store the number of collections for gen 0 in pressure[1].
* so i can avoid some comparison when doing this */
rtx->gc.ncolls[gen + 1]++; /* number of collections done for gen */
rtx->gc.ncolls[gen] = 0; /* reset the number of collections of the previous generation */
rtx->gc.ncolls[0] = 0; /* reset the number of allocations since last gc. this line is redundant if gen is 0. */
rtx->gc.pressure[gen + 1]++; /* number of collections done for gen */
rtx->gc.pressure[gen] = 0; /* reset the number of collections of the previous generation */
rtx->gc.pressure[0] = 0; /* reset the number of allocations since last gc. this line is redundant if gen is 0. */
#if defined(DEBUG_GC)
hawk_logbfmt (hawk_rtx_gethawk(rtx), HAWK_LOG_STDERR, "[GC] **ended**\n");
@ -355,7 +355,7 @@ static HAWK_INLINE int gc_collect_garbage_auto (hawk_rtx_t* rtx)
while (i > 1)
{
--i;
if (rtx->gc.ncolls[i] >= rtx->gc.threshold[i])
if (rtx->gc.pressure[i] >= rtx->gc.threshold[i])
{
gc_collect_garbage_in_generation (rtx, i);
return i;
@ -366,16 +366,17 @@ static HAWK_INLINE int gc_collect_garbage_auto (hawk_rtx_t* rtx)
return 0;
}
void hawk_rtx_gc (hawk_rtx_t* rtx, int gen)
int hawk_rtx_gc (hawk_rtx_t* rtx, int gen)
{
if (gen < 0)
{
gc_collect_garbage_auto (rtx);
return gc_collect_garbage_auto (rtx);
}
else
{
if (gen >= HAWK_COUNTOF(rtx->gc.g)) gen = HAWK_COUNTOF(rtx->gc.g) - 1;
gc_collect_garbage_in_generation (rtx, gen);
return gen;
}
}
@ -385,7 +386,7 @@ static HAWK_INLINE hawk_val_t* gc_calloc_val (hawk_rtx_t* rtx, hawk_oow_t size)
hawk_gch_t* gch;
int gc_gen = 0;
if (HAWK_UNLIKELY(rtx->gc.ncolls[0] >= rtx->gc.threshold[0]))
if (HAWK_UNLIKELY(rtx->gc.pressure[0] >= rtx->gc.threshold[0]))
{
/* invoke generational garbage collection */
gc_gen = gc_collect_garbage_auto(rtx);
@ -403,7 +404,7 @@ static HAWK_INLINE hawk_val_t* gc_calloc_val (hawk_rtx_t* rtx, hawk_oow_t size)
if (HAWK_UNLIKELY(!gch)) return HAWK_NULL;
}
rtx->gc.ncolls[0]++; /* increment of the number of allocation attempt */
rtx->gc.pressure[0]++; /* increment of the number of allocation attempt */
return hawk_gch_to_val(gch);
}