Support external context, heap and lcache (#1778)

JerryScript should support external context, heap and lcache,
so that it can have multiple instances and runtime configurable heap
size.

Related issue: 1746

JerryScript-DCO-1.0-Signed-off-by: Zidong Jiang zidong.jiang@intel.com
This commit is contained in:
Zidong Jiang
2017-05-20 11:00:19 +08:00
committed by GitHub
parent c6d890ee13
commit 5e28bfc28a
16 changed files with 319 additions and 21 deletions
+4
View File
@@ -55,6 +55,10 @@ macro(jerry_create_executable JERRY_NAME)
install(TARGETS ${JERRY_NAME} DESTINATION bin)
endmacro()
if(JERRY_LIBC AND FEATURE_EXTERNAL_CONTEXT)
MESSAGE(FATAL_ERROR "This configuration is not supported for jerry-main. Please build against your system libc to enable the external context.")
endif()
# Jerry standalones
if(JERRY_CMDLINE)
jerry_create_executable("jerry" "main-unix.c" "cli.c")
+24 -1
View File
@@ -390,6 +390,20 @@ check_usage (bool condition, /**< the condition that must hold */
}
} /* check_usage */
#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT
/**
* The alloc function passed to jerry_create_instance
*/
static void *
instance_alloc (size_t size,
void *cb_data_p __attribute__((unused)))
{
return malloc (size);
} /* instance_alloc */
#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */
int
main (int argc,
char **argv)
@@ -560,6 +574,13 @@ main (int argc,
is_repl_mode = true;
}
#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT
jerry_instance_t *instance_p = jerry_create_instance (512*1024, instance_alloc, NULL);
jerry_port_default_set_instance (instance_p);
#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */
jerry_init (flags);
register_js_function ("assert", jerryx_handler_assert);
@@ -764,6 +785,8 @@ main (int argc,
}
jerry_release_value (ret_value);
jerry_cleanup ();
#ifdef JERRY_ENABLE_EXTERNAL_CONTEXT
free (instance_p);
#endif /* JERRY_ENABLE_EXTERNAL_CONTEXT */
return ret_code;
} /* main */