Add logic from KeyedLoadIC generic stub to KeyedCallIC megamorphic stub.

This should make access faster for arrays of functions.

Review URL: http://codereview.chromium.org/2754003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4834 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e1e4d985
This diff is collapsed.
......@@ -58,7 +58,7 @@ static char TransitionMarkFromState(IC::State state) {
}
void IC::TraceIC(const char* type,
Handle<String> name,
Handle<Object> name,
State old_state,
Code* new_target,
const char* extra_info) {
......@@ -610,7 +610,8 @@ Object* KeyedCallIC::LoadFunction(State state,
if (object->IsString() || object->IsNumber() || object->IsBoolean()) {
ReceiverToObject(object);
} else {
}
if (FLAG_use_ic && state != MEGAMORPHIC && !object->IsAccessCheckNeeded()) {
int argc = target()->arguments_count();
InLoopFlag in_loop = target()->ic_in_loop();
......@@ -618,7 +619,10 @@ Object* KeyedCallIC::LoadFunction(State state,
argc, in_loop, Code::KEYED_CALL_IC);
if (!code->IsFailure()) {
set_target(Code::cast(code));
}
#ifdef DEBUG
TraceIC(
"KeyedCallIC", key, state, target(), in_loop ? " (in-loop)" : "");
#endif
}
}
Object* result = Runtime::GetObjectProperty(object, key);
......
......@@ -140,7 +140,7 @@ class IC {
#ifdef DEBUG
static void TraceIC(const char* type,
Handle<String> name,
Handle<Object> name,
State old_state,
Code* new_target,
const char* extra_info = "");
......
......@@ -126,6 +126,14 @@ namespace internal {
SC(keyed_load_generic_lookup_cache, V8.KeyedLoadGenericLookupCache) \
SC(keyed_load_generic_slow, V8.KeyedLoadGenericSlow) \
SC(keyed_load_external_array_slow, V8.KeyedLoadExternalArraySlow) \
/* How is the generic keyed-call stub used? */ \
SC(keyed_call_generic_smi_fast, V8.KeyedCallGenericSmiFast) \
SC(keyed_call_generic_smi_dict, V8.KeyedCallGenericSmiDict) \
SC(keyed_call_generic_lookup_cache, V8.KeyedCallGenericLookupCache) \
SC(keyed_call_generic_lookup_dict, V8.KeyedCallGenericLookupDict) \
SC(keyed_call_generic_value_type, V8.KeyedCallGenericValueType) \
SC(keyed_call_generic_slow, V8.KeyedCallGenericSlow) \
SC(keyed_call_generic_slow_load, V8.KeyedCallGenericSlowLoad) \
/* Count how much the monomorphic keyed-load stubs are hit. */ \
SC(keyed_load_function_prototype, V8.KeyedLoadFunctionPrototype) \
SC(keyed_load_string_length, V8.KeyedLoadStringLength) \
......
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * 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.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// '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 COPYRIGHT
// OWNER OR CONTRIBUTORS 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.
// A test for keyed call ICs with a mix of smi and string keys.
function testOne(receiver, key, result) {
for(var i = 0; i != 10; i++ ) {
assertEquals(result, receiver[key]());
}
}
function testMany(receiver, keys, results) {
for (var i = 0; i != 10; i++) {
for (var k = 0; k != keys.length; k++) {
assertEquals(results[k], receiver[keys[k]]());
}
}
}
var toStringNonSymbol = 'to';
toStringNonSymbol += 'String';
function TypeOfThis() { return typeof this; }
Number.prototype.square = function() { return this * this; }
Number.prototype.power4 = function() { return this.square().square(); }
Number.prototype.type = TypeOfThis;
String.prototype.type = TypeOfThis;
Boolean.prototype.type = TypeOfThis;
// Use a non-symbol key to force inline cache to generic case.
testOne(0, toStringNonSymbol, '0');
testOne(1, 'toString', '1');
testOne('1', 'toString', '1');
testOne(1.0, 'toString', '1');
testOne(1, 'type', 'object');
testOne(2.3, 'type', 'object');
testOne('x', 'type', 'object');
testOne(true, 'type', 'object');
testOne(false, 'type', 'object');
testOne(2, 'square', 4);
testOne(2, 'power4', 16);
function zero () { return 0; }
function one () { return 1; }
function two () { return 2; }
var fixed_array = [zero, one, two];
var dict_array = [ zero, one, two ];
dict_array[100000] = 1;
var fast_prop = { zero: zero, one: one, two: two };
var normal_prop = { zero: zero, one: one, two: two };
normal_prop.x = 0;
delete normal_prop.x;
var first3num = [0, 1, 2];
var first3str = ['zero', 'one', 'two'];
// Use a non-symbol key to force inline cache to generic case.
testMany('123', [toStringNonSymbol, 'charAt', 'charCodeAt'], ['123', '1', 49]);
testMany(fixed_array, first3num, first3num);
testMany(dict_array, first3num, first3num);
testMany(fast_prop, first3str, first3num);
testMany(normal_prop, first3str, first3num);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment