Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions aptos-move/aptos-vm-environment/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,13 @@ impl Environment {
gas_hook,
);
let natives = aptos_natives_with_builder(&mut builder, inject_create_signer_for_gov_sim);
let vm_config =
aptos_prod_vm_config(gas_feature_version, &features, &timed_features, ty_builder);
let vm_config = aptos_prod_vm_config(
chain_id,
gas_feature_version,
&features,
&timed_features,
ty_builder,
);
let verifier_bytes =
bcs::to_bytes(&vm_config.verifier_config).expect("Verifier config is serializable");
let runtime_environment = RuntimeEnvironment::new_with_config(natives, vm_config);
Expand Down
11 changes: 10 additions & 1 deletion aptos-move/aptos-vm-environment/src/prod_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use aptos_gas_schedule::{
AptosGasParameters,
};
use aptos_types::{
chain_id::ChainId,
on_chain_config::{
randomness_api_v0_config::{AllowCustomMaxGasFlag, RequiredGasDeposit},
FeatureFlag, Features, OnChainConfig, TimedFeatureFlag, TimedFeatureOverride,
Expand Down Expand Up @@ -171,6 +172,7 @@ pub fn aptos_prod_verifier_config(gas_feature_version: u64, features: &Features)
/// Returns [VMConfig] used by the Aptos blockchain in production, based on the set of feature
/// flags.
pub fn aptos_prod_vm_config(
chain_id: ChainId,
gas_feature_version: u64,
features: &Features,
timed_features: &TimedFeatures,
Expand Down Expand Up @@ -201,6 +203,12 @@ pub fn aptos_prod_vm_config(
let enable_capture_option = !timed_features.is_enabled(TimedFeatureFlag::DisabledCaptureOption)
|| features.is_enabled(FeatureFlag::ENABLE_CAPTURE_OPTION);

// Some feature gating was missed, so for native dynamic dispatch the feature is always on for
// testnet after 1.38 release.
let enable_function_caches = features.is_call_tree_and_instruction_vm_cache_enabled();
let enable_function_caches_for_native_dynamic_dispatch =
enable_function_caches || (chain_id.is_testnet() && gas_feature_version >= RELEASE_V1_38);

let config = VMConfig {
verifier_config,
deserializer_config,
Expand All @@ -218,7 +226,7 @@ pub fn aptos_prod_vm_config(
// manually where applicable.
delayed_field_optimization_enabled: false,
ty_builder,
enable_function_caches: features.is_call_tree_and_instruction_vm_cache_enabled(),
enable_function_caches,
enable_lazy_loading: features.is_lazy_loading_enabled(),
enable_depth_checks,
optimize_trusted_code: features.is_trusted_code_enabled(),
Expand All @@ -228,6 +236,7 @@ pub fn aptos_prod_vm_config(
enable_layout_caches,
propagate_dependency_limit_error: gas_feature_version >= RELEASE_V1_38,
enable_framework_for_option,
enable_function_caches_for_native_dynamic_dispatch,
};

// Note: if max_value_nest_depth changed, make sure the constant is in-sync. Do not remove this
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl GenesisRuntimeBuilder {
let timed_features = TimedFeaturesBuilder::enable_all().build();

let vm_config = aptos_prod_vm_config(
chain_id,
LATEST_GAS_FEATURE_VERSION,
&features,
&timed_features,
Expand Down
5 changes: 3 additions & 2 deletions aptos-move/block-executor/src/code_cache_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ where
}
}

/// A global module cache for verified code that is read-only and concurrently accessed during the
/// block execution. Modified safely only at block boundaries.
/// A global cache for verified code and derived information (such as layouts) that is concurrently
/// accessed during the block execution. Module cache is read-only, and modified safely only at
/// block boundaries. Layout cache can be modified during execution of the block.
pub struct GlobalModuleCache<K, D, V, E> {
/// Module cache containing the verified code.
module_cache: HashMap<K, Entry<D, V, E>>,
Expand Down
3 changes: 3 additions & 0 deletions third_party/move/move-vm/runtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub struct VMConfig {
pub enable_layout_caches: bool,
pub propagate_dependency_limit_error: bool,
pub enable_framework_for_option: bool,
/// Same as enable_function_caches, but gates missed gating for native dynamic dispatch.
pub enable_function_caches_for_native_dynamic_dispatch: bool,
}

impl Default for VMConfig {
Expand Down Expand Up @@ -78,6 +80,7 @@ impl Default for VMConfig {
enable_layout_caches: true,
propagate_dependency_limit_error: true,
enable_framework_for_option: true,
enable_function_caches_for_native_dynamic_dispatch: true,
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion third_party/move/move-vm/runtime/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,14 @@ where
}
}

let frame_cache = function_caches.get_or_create_frame_cache(&target_func);
let frame_cache = if self
.vm_config
.enable_function_caches_for_native_dynamic_dispatch
{
function_caches.get_or_create_frame_cache(&target_func)
} else {
FrameTypeCache::make_rc()
};
self.set_new_call_frame::<RTTCheck, RTRCheck>(
current_frame,
gas_meter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
processed 2 tasks
task 0 lines 1-31: publish --verbose [module 0x66::a]
task 1 lines 33-33: run 0x66::a::foo --verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//# publish --verbose
module 0x66::a
public fun take_fn<T>(a: T): T
local x: T
move_loc a
st_loc x
move_loc x
ret

public fun action(x: u8): u8
ld_u8 0
ret

public fun foo()
local fd: |u8|u8 has drop
local f: |u8|u8
pack_closure action, 0
st_loc f
ld_u8 1
move_loc f
call take_fn<|u8|u8>
call_closure<|u8|u8>
pop
pack_closure action, 0
st_loc fd
ld_u8 1
move_loc fd
call take_fn<|u8|u8 has drop>
call_closure<|u8|u8 has drop>
pop
ret

//# run 0x66::a::foo --verbose
13 changes: 11 additions & 2 deletions third_party/move/move-vm/types/src/ty_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! these caches is tied to the code cache, and is managed externally.

use crate::loaded_data::{runtime_types::Type, struct_name_indexing::StructNameIndex};
use move_core_types::ability::AbilitySet;
use parking_lot::RwLock;
use std::collections::HashMap;
use triomphe::Arc;
Expand Down Expand Up @@ -47,6 +48,9 @@ enum TypeRepr {
Function {
args: TypeVecId,
results: TypeVecId,
// Function types MUST carry abilities in order to be used correctly as type arguments.
// That is, `|| has drop` and `||` are different types.
abilities: AbilitySet,
},
}

Expand Down Expand Up @@ -281,7 +285,11 @@ impl InternedTypePool {
.collect::<Vec<_>>();
self.instantiated_struct_of(*idx, ty_args)
},
Function { args, results, .. } => {
Function {
args,
results,
abilities,
} => {
let args = args
.iter()
.map(|t| self.instantiate_and_intern(t, subst))
Expand All @@ -293,6 +301,7 @@ impl InternedTypePool {
self.ty_interner.intern(TypeRepr::Function {
args: self.ty_vec_interner.intern_vec(args),
results: self.ty_vec_interner.intern_vec(results),
abilities: *abilities,
})
},
}
Expand Down Expand Up @@ -465,7 +474,7 @@ mod test {
abilities: AbilitySet::ALL,
};
let id4 = ctx.instantiate_and_intern(&func_ty, &[]);
assert_eq!(id3, id4);
assert_ne!(id3, id4);
}

#[test]
Expand Down
Loading