Compact Byte Code parser and executor for Jerry.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Tamas Gergely tgergely.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély zsborbely.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2016-02-05 00:10:10 -08:00
parent db6caf3c48
commit 4d2dd22ced
92 changed files with 17184 additions and 20276 deletions
+2 -22
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
#include "jrt.h"
#include "jrt-libc-includes.h"
#include "jrt-bit-fields.h"
#include "vm-defines.h"
#include "vm-stack.h"
#define JERRY_INTERNAL
@@ -335,13 +336,11 @@ ecma_gc_mark (ecma_object_t *object_p) /**< object to mark from */
JERRY_UNREACHABLE ();
}
case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* a collection of strings */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE: /* compressed pointer to a ecma_number_t */
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE: /* a simple boolean value */
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */
case ECMA_INTERNAL_PROPERTY_CODE_FLAGS_AND_OFFSET: /* an integer */
case ECMA_INTERNAL_PROPERTY_NATIVE_CODE: /* an external pointer */
case ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE: /* an external pointer */
case ECMA_INTERNAL_PROPERTY_FREE_CALLBACK: /* an object's native free callback */
@@ -484,25 +483,6 @@ ecma_gc_run (void)
}
}
/* if some object is referenced from a register variable (i.e. it is root),
* start recursive marking traverse from the object */
for (vm_stack_frame_t *frame_iter_p = vm_stack_get_top_frame ();
frame_iter_p != NULL;
frame_iter_p = frame_iter_p->prev_frame_p)
{
for (uint32_t reg_index = 0; reg_index < frame_iter_p->regs_number; reg_index++)
{
ecma_value_t reg_value = vm_stack_frame_get_reg_value (frame_iter_p, VM_REG_FIRST + reg_index);
if (ecma_is_value_object (reg_value))
{
ecma_object_t *obj_p = ecma_get_object_from_value (reg_value);
ecma_gc_set_object_visited (obj_p, true);
}
}
}
bool marked_anything_during_current_iteration = false;
do
+20 -15
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,6 +82,7 @@ typedef enum
but are stored directly in the array's property list
(used for array elements with non-default attribute values) */
ECMA_SIMPLE_VALUE_ARRAY_HOLE, /**< array hole, used for initialization of an array literal */
ECMA_SIMPLE_VALUE_REGISTER_REF, /**< register reference, a special "base" value for vm */
ECMA_SIMPLE_VALUE__COUNT /** count of simple ecma-values */
} ecma_simple_value_t;
@@ -170,21 +171,12 @@ typedef uint32_t ecma_completion_value_t;
#define ECMA_COMPLETION_VALUE_VALUE_POS (0)
#define ECMA_COMPLETION_VALUE_VALUE_WIDTH (ECMA_VALUE_SIZE)
/**
* Break / continue jump target
*/
#define ECMA_COMPLETION_VALUE_TARGET_POS (0)
#define ECMA_COMPLETION_VALUE_TARGET_WIDTH ((uint32_t) sizeof (vm_instr_counter_t) * JERRY_BITSINBYTE)
/**
* Type (ecma_completion_type_t)
*/
#define ECMA_COMPLETION_VALUE_TYPE_POS (JERRY_MAX (JERRY_ALIGNUP (ECMA_COMPLETION_VALUE_VALUE_POS + \
#define ECMA_COMPLETION_VALUE_TYPE_POS (JERRY_ALIGNUP (ECMA_COMPLETION_VALUE_VALUE_POS + \
ECMA_COMPLETION_VALUE_VALUE_WIDTH, \
JERRY_BITSINBYTE), \
JERRY_ALIGNUP (ECMA_COMPLETION_VALUE_TARGET_POS + \
ECMA_COMPLETION_VALUE_TARGET_WIDTH, \
JERRY_BITSINBYTE)))
JERRY_BITSINBYTE))
#define ECMA_COMPLETION_VALUE_TYPE_WIDTH (8)
/**
@@ -218,12 +210,9 @@ typedef enum
ECMA_INTERNAL_PROPERTY_SCOPE, /**< [[Scope]] */
ECMA_INTERNAL_PROPERTY_PARAMETERS_MAP, /**< [[ParametersMap]] */
ECMA_INTERNAL_PROPERTY_CODE_BYTECODE, /**< first part of [[Code]] - compressed pointer to bytecode array */
ECMA_INTERNAL_PROPERTY_CODE_FLAGS_AND_OFFSET, /**< second part of [[Code]] - offset in bytecode array and code flags
* (see also: ecma_pack_code_internal_property_value) */
ECMA_INTERNAL_PROPERTY_NATIVE_CODE, /**< native handler location descriptor */
ECMA_INTERNAL_PROPERTY_NATIVE_HANDLE, /**< native handle associated with an object */
ECMA_INTERNAL_PROPERTY_FREE_CALLBACK, /**< object's native free callback */
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS, /**< [[FormalParameters]] */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE, /**< [[Primitive value]] for String objects */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE, /**< [[Primitive value]] for Number objects */
ECMA_INTERNAL_PROPERTY_PRIMITIVE_BOOLEAN_VALUE, /**< [[Primitive value]] for Boolean objects */
@@ -837,6 +826,22 @@ typedef struct ecma_string_t
*/
typedef uintptr_t ecma_external_pointer_t;
/**
* Compiled byte code data.
*/
typedef struct
{
uint16_t status_flags; /**< various status flags */
} ecma_compiled_code_t;
/**
* Shift value for byte code reference counting.
* The last 10 bit of the first uint16_t value
* of compact byte code or regexp byte code
* is reserved for reference counting.
*/
#define ECMA_BYTECODE_REF_SHIFT 6
/**
* @}
*/
+3 -3
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
* @{
*/
#include "bytecode-data.h"
#include "ecma-alloc.h"
#include "ecma-gc.h"
#include "ecma-globals.h"
@@ -29,9 +28,10 @@
#include "jrt.h"
#include "jrt-libc-includes.h"
#include "lit-char-helpers.h"
#include "lit-literal.h"
#include "lit-magic-strings.h"
#include "vm.h"
#include "rcs-records.h"
#include "vm.h"
/**
* Maximum length of strings' concatenation
+3 -63
View File
@@ -1,4 +1,4 @@
/* Copyright 2015 Samsung Electronics Co., Ltd.
/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,16 +26,16 @@
#include "ecma-helpers.h"
#include "jrt.h"
#include "jrt-bit-fields.h"
#include "vm-defines.h"
JERRY_STATIC_ASSERT (sizeof (ecma_value_t) * JERRY_BITSINBYTE >= ECMA_VALUE_SIZE);
JERRY_STATIC_ASSERT (sizeof (ecma_completion_value_t) * JERRY_BITSINBYTE >= ECMA_COMPLETION_VALUE_SIZE);
/**
* Get type field of ecma-value
*
* @return type field
*/
static ecma_type_t __attr_pure___
ecma_type_t __attr_pure___
ecma_get_value_type_field (ecma_value_t value) /**< ecma-value */
{
return (ecma_type_t) jrt_extract_bit_field (value,
@@ -474,19 +474,6 @@ ecma_get_completion_value_value_field (ecma_completion_value_t completion_value)
ECMA_COMPLETION_VALUE_VALUE_WIDTH);
} /* ecma_get_completion_value_value_field */
/**
* Get target of break / continue completion value
*
* @return instruction counter
*/
static vm_instr_counter_t
ecma_get_completion_value_target (ecma_completion_value_t completion_value) /**< completion value */
{
return (vm_instr_counter_t) jrt_extract_bit_field (completion_value,
ECMA_COMPLETION_VALUE_TARGET_POS,
ECMA_COMPLETION_VALUE_TARGET_WIDTH);
} /* ecma_get_completion_value_target */
/**
* Set type field of completion value
*
@@ -519,21 +506,6 @@ ecma_set_completion_value_value_field (ecma_completion_value_t completion_value,
ECMA_COMPLETION_VALUE_VALUE_WIDTH);
} /* ecma_set_completion_value_value_field */
/**
* Set target of break / continue completion value
*
* @return completion value with updated field
*/
static ecma_completion_value_t __attr_const___
ecma_set_completion_value_target (ecma_completion_value_t completion_value, /**< completion value
* to set field in */
vm_instr_counter_t target) /**< break / continue target */
{
return (ecma_completion_value_t) jrt_set_bit_field_value (completion_value,
target,
ECMA_COMPLETION_VALUE_TARGET_POS,
ECMA_COMPLETION_VALUE_TARGET_WIDTH);
} /* ecma_set_completion_value_target */
/**
* Normal, throw, return, exit and meta completion values constructor
@@ -652,24 +624,6 @@ ecma_make_meta_completion_value (void)
ecma_make_simple_value (ECMA_SIMPLE_VALUE_EMPTY));
} /* ecma_make_meta_completion_value */
/**
* Break / continue completion values constructor
*
* @return completion value
*/
ecma_completion_value_t __attr_const___
ecma_make_jump_completion_value (vm_instr_counter_t target) /**< target break / continue */
{
ecma_completion_value_t completion_value = 0;
completion_value = ecma_set_completion_value_type_field (completion_value,
ECMA_COMPLETION_TYPE_JUMP);
completion_value = ecma_set_completion_value_target (completion_value,
target);
return completion_value;
} /* ecma_make_jump_completion_value */
/**
* Get ecma-value from specified completion value
*
@@ -722,20 +676,6 @@ ecma_get_object_from_completion_value (ecma_completion_value_t completion_value)
return ecma_get_object_from_value (ecma_get_completion_value_value (completion_value));
} /* ecma_get_object_from_completion_value */
/**
* Get break / continue target from completion value
*
* @return instruction counter
*/
vm_instr_counter_t
ecma_get_jump_target_from_completion_value (ecma_completion_value_t completion_value) /**< completion
* value */
{
JERRY_ASSERT (ecma_get_completion_value_type_field (completion_value) == ECMA_COMPLETION_TYPE_JUMP);
return ecma_get_completion_value_target (completion_value);
} /* ecma_get_jump_target_from_completion_value */
/**
* Copy ecma-completion value.
*
+102 -19
View File
@@ -1,4 +1,5 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +27,8 @@
#include "ecma-helpers.h"
#include "ecma-lcache.h"
#include "jrt-bit-fields.h"
#include "byte-code.h"
#include "re-compiler.h"
/**
* Create an object with specified prototype object
@@ -763,17 +766,6 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
break;
}
case ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS: /* a strings' collection */
{
if (property_value != ECMA_NULL_POINTER)
{
ecma_free_values_collection (ECMA_GET_NON_NULL_POINTER (ecma_collection_header_t,
property_value),
false);
}
break;
}
case ECMA_INTERNAL_PROPERTY_PRIMITIVE_STRING_VALUE: /* compressed pointer to a ecma_string_t */
{
ecma_string_t *str_p = ECMA_GET_NON_NULL_POINTER (ecma_string_t,
@@ -807,8 +799,6 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
case ECMA_INTERNAL_PROPERTY_PROTOTYPE: /* the property's value is located in ecma_object_t */
case ECMA_INTERNAL_PROPERTY_EXTENSIBLE: /* the property's value is located in ecma_object_t */
case ECMA_INTERNAL_PROPERTY_CLASS: /* an enum */
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */
case ECMA_INTERNAL_PROPERTY_CODE_FLAGS_AND_OFFSET: /* an integer */
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ID: /* an integer */
case ECMA_INTERNAL_PROPERTY_BUILT_IN_ROUTINE_DESC: /* an integer */
case ECMA_INTERNAL_PROPERTY_EXTENSION_ID: /* an integer */
@@ -840,15 +830,24 @@ ecma_free_internal_property (ecma_property_t *property_p) /**< the property */
* but number of the real internal property types */
{
JERRY_UNREACHABLE ();
break;
}
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE:
{
void *bytecode_p = ECMA_GET_POINTER (void, property_value);
if (bytecode_p)
case ECMA_INTERNAL_PROPERTY_CODE_BYTECODE: /* compressed pointer to a bytecode array */
{
ecma_bytecode_deref (ECMA_GET_NON_NULL_POINTER (ecma_compiled_code_t, property_value));
break;
}
case ECMA_INTERNAL_PROPERTY_REGEXP_BYTECODE: /* compressed pointer to a regexp bytecode array */
{
ecma_compiled_code_t *bytecode_p = ECMA_GET_POINTER (ecma_compiled_code_t, property_value);
if (bytecode_p != NULL)
{
mem_heap_free_block (bytecode_p);
ecma_bytecode_deref (bytecode_p);
}
break;
}
}
@@ -1328,6 +1327,90 @@ ecma_get_property_descriptor_from_property (ecma_property_t *prop_p) /**< proper
return prop_desc;
} /* ecma_get_property_descriptor_from_property */
/**
* Increase reference counter of Compact
* Byte Code or regexp byte code.
*/
void
ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
{
/* Abort program if maximum reference number is reached.
* Note: This is not tested for objects. */
if ((bytecode_p->status_flags >> ECMA_BYTECODE_REF_SHIFT) >= 0x3ff)
{
jerry_fatal (ERR_UNIMPLEMENTED_CASE);
}
bytecode_p->status_flags = (uint16_t) (bytecode_p->status_flags + (1 << ECMA_BYTECODE_REF_SHIFT));
} /* ecma_bytecode_ref */
/**
* Decrease reference counter of Compact
* Byte Code or regexp byte code.
*/
void
ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
{
JERRY_ASSERT ((bytecode_p->status_flags >> ECMA_BYTECODE_REF_SHIFT) > 0);
bytecode_p->status_flags = (uint16_t) (bytecode_p->status_flags - (1 << ECMA_BYTECODE_REF_SHIFT));
if (bytecode_p->status_flags >= (1 << ECMA_BYTECODE_REF_SHIFT))
{
/* Non-zero reference counter. */
return;
}
if (bytecode_p->status_flags & CBC_CODE_FLAGS_FUNCTION)
{
lit_cpointer_t *literal_start_p = NULL;
uint32_t literal_end;
uint32_t const_literal_end;
if (bytecode_p->status_flags & CBC_CODE_FLAGS_UINT16_ARGUMENTS)
{
uint8_t *byte_p = (uint8_t *) bytecode_p;
literal_start_p = (lit_cpointer_t *) (byte_p + sizeof (cbc_uint16_arguments_t));
cbc_uint16_arguments_t *args_p = (cbc_uint16_arguments_t *) bytecode_p;
literal_end = args_p->literal_end;
const_literal_end = args_p->const_literal_end;
}
else
{
uint8_t *byte_p = (uint8_t *) bytecode_p;
literal_start_p = (lit_cpointer_t *) (byte_p + sizeof (cbc_uint8_arguments_t));
cbc_uint8_arguments_t *args_p = (cbc_uint8_arguments_t *) bytecode_p;
literal_end = args_p->literal_end;
const_literal_end = args_p->const_literal_end;
}
for (uint32_t i = const_literal_end; i < literal_end; i++)
{
mem_cpointer_t bytecode_cpointer = literal_start_p[i].value.base_cp;
ecma_compiled_code_t *bytecode_literal_p = ECMA_GET_NON_NULL_POINTER (ecma_compiled_code_t,
bytecode_cpointer);
/* Self references are ignored. */
if (bytecode_literal_p != bytecode_p)
{
ecma_bytecode_deref (bytecode_literal_p);
}
}
}
else
{
#ifndef CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN
re_compiled_code_t *re_bytecode_p = (re_compiled_code_t *) bytecode_p;
ecma_deref_ecma_string (ECMA_GET_NON_NULL_POINTER (ecma_string_t, re_bytecode_p->pattern_cp));
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
}
mem_heap_free_block (bytecode_p);
} /* ecma_bytecode_deref */
/**
* @}
* @}
+7 -5
View File
@@ -1,5 +1,5 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
* Copyright 2015 University of Szeged.
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
* Copyright 2015-2016 University of Szeged.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@
#include "ecma-globals.h"
#include "lit-strings.h"
#include "mem-allocator.h"
#include "opcodes.h"
/**
* Get value of pointer from specified non-null compressed pointer.
@@ -53,6 +52,8 @@
#define ECMA_SET_POINTER(field, non_compressed_pointer) MEM_CP_SET_POINTER (field, non_compressed_pointer)
/* ecma-helpers-value.cpp */
extern ecma_type_t ecma_get_value_type_field (ecma_value_t) __attr_pure___;
extern bool ecma_is_value_empty (ecma_value_t);
extern bool ecma_is_value_undefined (ecma_value_t);
extern bool ecma_is_value_null (ecma_value_t);
@@ -84,12 +85,10 @@ extern ecma_completion_value_t ecma_make_throw_obj_completion_value (ecma_object
extern ecma_completion_value_t ecma_make_empty_completion_value (void);
extern ecma_completion_value_t ecma_make_return_completion_value (ecma_value_t);
extern ecma_completion_value_t ecma_make_meta_completion_value (void);
extern ecma_completion_value_t ecma_make_jump_completion_value (vm_instr_counter_t);
extern ecma_value_t ecma_get_completion_value_value (ecma_completion_value_t);
extern ecma_number_t *ecma_get_number_from_completion_value (ecma_completion_value_t) __attr_const___;
extern ecma_string_t *ecma_get_string_from_completion_value (ecma_completion_value_t) __attr_const___;
extern ecma_object_t *ecma_get_object_from_completion_value (ecma_completion_value_t) __attr_const___;
extern vm_instr_counter_t ecma_get_jump_target_from_completion_value (ecma_completion_value_t);
extern ecma_completion_value_t ecma_copy_completion_value (ecma_completion_value_t);
extern void ecma_free_completion_value (ecma_completion_value_t);
@@ -254,6 +253,9 @@ extern ecma_property_descriptor_t ecma_make_empty_property_descriptor (void);
extern void ecma_free_property_descriptor (ecma_property_descriptor_t *);
extern ecma_property_descriptor_t ecma_get_property_descriptor_from_property (ecma_property_t *);
extern void ecma_bytecode_ref (ecma_compiled_code_t *);
extern void ecma_bytecode_deref (ecma_compiled_code_t *);
/* ecma-helpers-external-pointers.cpp */
extern bool
ecma_create_external_pointer_property (ecma_object_t *, ecma_internal_property_id_t, ecma_external_pointer_t);
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
/* Copyright 2014-2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,8 +50,8 @@ ecma_finalize (void)
mem_unregister_a_try_give_memory_back_callback (ecma_try_to_give_back_some_memory);
ecma_finalize_environment ();
ecma_finalize_builtins ();
ecma_lcache_invalidate_all ();
ecma_finalize_builtins ();
ecma_gc_run ();
} /* ecma_finalize */