blob: cb7b07c2ce3c49478a42c4293ff0e9703d8cd56d [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library kernel.vm.native_effects;
import 'dart:io';
import '../transformations/treeshaker.dart';
typedef void _EffectsHandler(NativeEffectsHandler effects);
void NoEffect(NativeEffectsHandler effects) {}
void StringAllocationEffect(NativeEffectsHandler effects) {
effects.markAllocated('dart:core', '_OneByteString');
effects.markAllocated('dart:core', '_TwoByteString');
}
_EffectsHandler AllocatesClassEffect(String library, String klass) {
return (NativeEffectsHandler effects) {
effects.markAllocated(library, klass);
};
}
void AllocatesListEffect(NativeEffectsHandler effects) {
effects.markAllocated('dart:core', '_GrowableList');
effects.markAllocated('dart:core', '_List');
}
_EffectsHandler AllocatesListEffectX(String suffix) {
return (NativeEffectsHandler effects) {
effects.markAllocated('dart:core', '_GrowableList%${suffix}');
effects.markAllocated('dart:core', '_List%${suffix}');
};
}
class VmNativeEffects implements NativeEffects {
final Map<String, _EffectsHandler> nativeEffects = <String, _EffectsHandler>{
'List_allocate': AllocatesClassEffect('dart:core', '_List'),
'List_getIndexed': NoEffect,
'List_setIndexed': NoEffect,
'List_getLength': NoEffect,
'List_slice': AllocatesClassEffect('dart:core', '_List'),
'List_allocate%I': AllocatesClassEffect('dart:core', '_List%I'),
'List_getIndexed%I': NoEffect,
'List_setIndexed%I': NoEffect,
'List_getLength%I': NoEffect,
'List_slice%I': AllocatesClassEffect('dart:core', '_List%I'),
'GrowableList_allocate%I': AllocatesListEffectX('I'),
'GrowableList_allocate': AllocatesListEffect,
'GrowableList_setLength': NoEffect,
'GrowableList_getIndexed': NoEffect,
'GrowableList_setIndexed': NoEffect,
'GrowableList_getLength': NoEffect,
'GrowableList_getCapacity': NoEffect,
'GrowableList_setData': NoEffect,
'GrowableList_getData': NoEffect,
'GrowableList_setLength%I': NoEffect,
'GrowableList_getIndexed%I': NoEffect,
'GrowableList_setIndexed%I': NoEffect,
'GrowableList_getLength%I': NoEffect,
'GrowableList_getCapacity%I': NoEffect,
'GrowableList_setData%I': NoEffect,
'GrowableList_getData%I': NoEffect,
'DateTime_currentTimeMicros': NoEffect,
'LinkedHashMap_getIndex': NoEffect,
'LinkedHashMap_setIndex': NoEffect,
'LinkedHashMap_getHashMask': NoEffect,
'LinkedHashMap_setHashMask': NoEffect,
'LinkedHashMap_setData': NoEffect,
'LinkedHashMap_getUsedData': NoEffect,
'LinkedHashMap_setUsedData': NoEffect,
'LinkedHashMap_getDeletedKeys': NoEffect,
'LinkedHashMap_setDeletedKeys': NoEffect,
'LinkedHashMap_getData': NoEffect,
'Identical_comparison': NoEffect,
'String_getLength': NoEffect,
'String_concat': NoEffect,
'String_codeUnitAt': NoEffect,
'String_getHashCode': NoEffect,
'Object_vipunenDoubleFromInt': NoEffect,
'Object_vipunenGC': NoEffect,
'Object_vipunenNativeTest': NoEffect,
'Object_vipunenPrintInt': NoEffect,
'Object_vipunenTraverseStack': NoEffect,
'Object_vipunenPrintDouble': NoEffect,
'Object_equals': NoEffect,
'Object_toString': StringAllocationEffect,
'OneByteString_allocate': StringAllocationEffect,
'OneByteString_setAt': NoEffect,
'StringBuffer_createStringFromUint16Array': StringAllocationEffect,
'String_concatRange': StringAllocationEffect,
'Stopwatch_now': NoEffect,
'Stopwatch_frequency': NoEffect,
'Double_ceil': NoEffect,
'Double_mul': NoEffect,
'Double_toInt': NoEffect,
'Double_toString': StringAllocationEffect,
'File_Open': AllocatesClassEffect('dart:io', '_File'),
'File_SetPointer': NoEffect,
'File_Length': NoEffect,
'File_Read': AllocatesClassEffect('dart:typed_data', '_Uint8List'),
'File_Close': NoEffect,
'TypedData_setRange': NoEffect,
'Integer_addFromInteger': NoEffect,
'Smi_bitLength': NoEffect,
'Mint_bitNegate': NoEffect,
'Mint_bitLength': NoEffect,
'Mint_shlFromInt': NoEffect,
'ClassID_getID': NoEffect,
'Internal_makeListFixedLength': AllocatesClassEffect('dart:core', '_List'),
'Random_setupSeed': NoEffect,
'Random_nextState': NoEffect,
'Random_initialSeed': NoEffect,
'TypedData_length': NoEffect,
'TypedData_SetInt64': NoEffect,
'TypedData_GetInt64': NoEffect,
'TypedData_GetUint8': NoEffect,
'TypedData_SetUint8': NoEffect,
'TypedData_GetUint32': NoEffect,
'TypedData_SetUint32': NoEffect,
'Internal_inquireIs64Bit': NoEffect,
'Object_getHash': NoEffect,
'Object_setHash': NoEffect,
'TypedData_Uint8Array_new':
AllocatesClassEffect('dart:typed_data', '_Uint8List'),
'TypedData_Int64Array_new':
AllocatesClassEffect('dart:typed_data', '_Int64List'),
'TypedData_Uint32Array_new':
AllocatesClassEffect('dart:typed_data', '_Uint32List'),
'TypedData_Uint16Array_new':
AllocatesClassEffect('dart:typed_data', '_Uint16List'),
'Object_vipunenStringInterpolate': StringAllocationEffect,
'Closure_computeHash' : NoEffect,
// These are for now only used for making package:kernel's (less agressive)
// tree shaker work.
'Async_rethrow': NoEffect,
'Bigint_allocate': AllocatesClassEffect('dart:core', '_Bigint'),
'Bool_fromEnvironment': NoEffect,
'DateTime_timeZoneOffsetInSeconds': NoEffect,
'Developer_lookupExtension': NoEffect,
'Developer_registerExtension': NoEffect,
'Double_add': NoEffect,
'Double_div': NoEffect,
'Double_doubleFromInteger': NoEffect,
'Double_equal': NoEffect,
'Double_equalToInteger': NoEffect,
'Double_flipSignBit': NoEffect,
'Double_floor': NoEffect,
'Double_getIsInfinite': NoEffect,
'Double_getIsNaN': NoEffect,
'Double_getIsNegative': NoEffect,
'Double_greaterThanFromInteger': NoEffect,
'Double_greaterThan': NoEffect,
'Double_modulo': NoEffect,
'Double_parse': NoEffect,
'Double_remainder': NoEffect,
'Double_round': NoEffect,
'Double_sub': NoEffect,
'Double_toStringAsExponential': StringAllocationEffect,
'Double_toStringAsFixed': StringAllocationEffect,
'Double_toStringAsPrecision': StringAllocationEffect,
'Double_truncate': NoEffect,
'Double_trunc_div': NoEffect,
'Double_hashCode': NoEffect,
'File_Flush': NoEffect,
'File_GetPointer': NoEffect,
'File_LengthFromPath': NoEffect,
'ImmutableList_from': AllocatesClassEffect('dart:core', '_ImmutableList'),
'IOService_NewServicePort': NoEffect,
'Integer_toDouble': NoEffect,
'Integer_add': NoEffect,
'Integer_bitAnd': NoEffect,
'Integer_bitLength': NoEffect,
'Integer_bitNot': NoEffect,
'Integer_bitOr': NoEffect,
'Integer_bitOrFromInteger': NoEffect,
'Integer_bitXor': NoEffect,
'Integer_bitXorFromInteger': NoEffect,
'Integer_equal': NoEffect,
'Integer_equalToInteger': NoEffect,
'Integer_greaterThan': NoEffect,
'Integer_greaterThanFromInteger': NoEffect,
'Integer_mod': NoEffect,
'Integer_moduloFromInteger': NoEffect,
'Integer_mul': NoEffect,
'Integer_mulFromInteger': NoEffect,
'Integer_remainder': NoEffect,
'Integer_shl': NoEffect,
'Integer_shr': NoEffect,
'Integer_sub': NoEffect,
'Integer_subFromInteger': NoEffect,
'Integer_truncDiv': NoEffect,
'Integer_truncDivFromInteger': NoEffect,
'Integer_unaryMinus': NoEffect,
'Integer_fromEnvironment': NoEffect,
'Object_as': NoEffect,
'Object_instanceOf': NoEffect,
'Object_noSuchMethod': NoEffect,
'Object_runtimeType': NoEffect,
'Object_simpleInstanceOf': NoEffect,
'OneByteString_splitWithCharCode': StringAllocationEffect,
'OneByteString_substringUnchecked': StringAllocationEffect,
'RawReceivePortImpl_factory': NoEffect,
'RegExp_factory': AllocatesClassEffect('dart:core', '_RegExp'),
'Smi_bitAndFromSmi': NoEffect,
'Smi_bitNegate': NoEffect,
'Smi_shlFromInt': NoEffect,
'Smi_shrFromInt': NoEffect,
'StringBase_createFromCodePoints': StringAllocationEffect,
'StringBase_joinReplaceAllResult': StringAllocationEffect,
'StringBase_substringUnchecked': StringAllocationEffect,
'String_charAt': StringAllocationEffect,
'String_toLowerCase': StringAllocationEffect,
'String_toUpperCase': StringAllocationEffect,
'TwoByteString_allocateFromTwoByteList':
AllocatesClassEffect('dart:core', '_TwoByteString'),
'TypedData_GetUint16': NoEffect,
'TypedData_SetUint16': NoEffect,
'Bigint_getDigits': NoEffect,
'Bigint_getNeg': NoEffect,
'Bigint_getUsed': NoEffect,
'Integer_bitAndFromInteger': NoEffect,
'RegExp_ExecuteMatch': AllocatesListEffect,
'RegExp_ExecuteMatchSticky': AllocatesListEffect,
'RegExp_getGroupCount': NoEffect,
'Closure_equals': NoEffect,
'Closure_hashCode': NoEffect,
'NoSuchMethodError_existingMethodSignature': StringAllocationEffect,
'InvocationMirror_unpackTypeArguments': AllocatesListEffect,
};
void getEffectsFor(String nativeName, NativeEffectsHandler effects) {
final _EffectsHandler handler = nativeEffects[nativeName];
if (handler == null) {
throw 'No native effect registered for native "$nativeName"';
}
handler(effects);
}
}