| // 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'); |
| } |
| |
| class VmNativeEffects implements NativeEffects { |
| final Map<String, _EffectsHandler> nativeEffects = <String, _EffectsHandler>{ |
| 'List_allocate': AllocatesClassEffect('dart:core', '_List'), |
| 'List_getIndexed': NoEffect, |
| 'List_setIndexed': NoEffect, |
| 'GrowableList_allocate': AllocatesListEffect, |
| 'GrowableList_setLength': NoEffect, |
| 'GrowableList_getIndexed': NoEffect, |
| 'GrowableList_setIndexed': NoEffect, |
| 'GrowableList_getLength': NoEffect, |
| 'GrowableList_getCapacity': NoEffect, |
| 'GrowableList_setData': NoEffect, |
| 'GrowableList_getData': 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, |
| 'List_getLength': NoEffect, |
| 'List_slice': 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, |
| |
| // 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, |
| 'Closure_invoke': 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, |
| 'File_Flush': NoEffect, |
| 'File_GetPointer': NoEffect, |
| 'File_LengthFromPath': NoEffect, |
| 'ImmutableList_from': AllocatesClassEffect('dart:core', '_ImmutableList'), |
| 'Integer_bitOrFromInteger': NoEffect, |
| 'Integer_bitXorFromInteger': NoEffect, |
| 'Integer_equalToInteger': NoEffect, |
| 'Integer_greaterThanFromInteger': NoEffect, |
| 'Integer_moduloFromInteger': NoEffect, |
| 'Integer_mulFromInteger': NoEffect, |
| 'Integer_subFromInteger': NoEffect, |
| 'Integer_truncDivFromInteger': NoEffect, |
| 'IOService_NewServicePort': NoEffect, |
| 'Object_as': NoEffect, |
| 'Object_instanceOf': NoEffect, |
| 'Object_noSuchMethod': NoEffect, |
| 'Object_runtimeType': NoEffect, |
| 'Object_simpleInstanceOf': NoEffect, |
| 'OneByteString_splitWithCharCode': StringAllocationEffect, |
| 'OneByteString_substringUnchecked': StringAllocationEffect, |
| 'RawReceivePortImpl_factory': AllocatesClassEffect('dart:isolate', '_RawReceivePortImpl'), |
| 'RawReceivePortImpl_get_id': NoEffect, |
| 'RawReceivePortImpl_get_sendport': NoEffect, |
| 'RawReceivePortImpl_closeInternal': 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, |
| }; |
| |
| void getEffectsFor(String nativeName, NativeEffectsHandler effects) { |
| final _EffectsHandler handler = nativeEffects[nativeName]; |
| if (handler == null) { |
| throw 'No native effect registered for native "$nativeName"'; |
| } |
| handler(effects); |
| } |
| } |