Skip to content
Permalink
Browse files
impl mem checker (#171, DFI-626)
* Implements lru cache.

* added mem checker test.
  • Loading branch information
RIg410 committed Aug 27, 2020
1 parent 3b294ed commit 334e345234fadd1440e26fbf3a3f58f2dce86edc
Show file tree
Hide file tree
Showing 20 changed files with 776 additions and 128 deletions.

Large diffs are not rendered by default.

@@ -17,6 +17,7 @@ libra = { path = "../libra", package = "dvm-libra-deps" }
compiler = { path = "../compiler", package = "dvm-compiler" }
dvm-net = { path = "../net" }
dvm-info = { path = "../info" }
runtime = { path = "../runtime", package = "dvm-runtime" }

anyhow = "1.0"
log = "0.4.8"
@@ -29,10 +29,10 @@ use services::vm::VmService;
use dvm_cli::config::*;
use dvm_cli::init;
use futures::join;
use dvm_info::config::InfoServiceConfig;
use dvm_info::config::{InfoServiceConfig, MemoryOptions};
use dvm_cli::info_service::create_info_service;

const MODULE_CACHE: usize = 1000;
use dvm_info::memory_check::MemoryChecker;
use runtime::vm::dvm::Dvm;

/// Definance Virtual Machine
/// combined with Move compilation server
@@ -56,6 +56,9 @@ struct Options {
#[clap(flatten)]
info_service: InfoServiceConfig,

#[clap(flatten)]
memory_config: MemoryOptions,

/// DataSource Server internet address.
#[clap(
name = "Data-Source URI",
@@ -100,9 +103,10 @@ async fn main_internal(options: Options) -> Result<()> {
// data-source client
let ds = GrpcDataSource::new(options.ds, Some(ds_term_rx))
.expect("Unable to instantiate GrpcDataSource.");
let ds = ModuleCache::new(DsMeter::new(ds), MODULE_CACHE);
let ds = ModuleCache::new(DsMeter::new(ds), options.memory_config.module_cache());
let mem_checker = MemoryChecker::new(options.memory_config, vec![Box::new(ds.clone())]);
// vm services
let vm_service = VmService::new(ds.clone(), hrm);
let vm_service = VmService::new(Dvm::new(ds.clone(), Some(mem_checker)), hrm);
// comp services
let compiler_service = CompilerService::new(Compiler::new(ds));
let metadata_service = MetadataService::default();
@@ -19,4 +19,3 @@ crossbeam = "0.7.3"
http = "0.2"
tokio = { version = "0.2", features = [ "macros", "rt-core", "rt-threaded", "blocking", "full" ] }
log = "0.4.8"
lru = "0.4.3"
@@ -1,4 +1,4 @@
use crate::{DataSource, Clear};
use crate::{DataSource, RemoveModule};
use std::collections::HashSet;
use libra::prelude::*;

@@ -64,11 +64,11 @@ where

impl<D> DataSource for BlackListDataSource<D> where D: DataSource {}

impl<D> Clear for BlackListDataSource<D>
impl<D> RemoveModule for BlackListDataSource<D>
where
D: DataSource,
{
fn clear(&self) {
self.inner.clear();
fn remove_module(&self, module_id: &ModuleId) {
self.inner.remove_module(module_id)
}
}
@@ -14,7 +14,7 @@ use dvm_net::api;
use dvm_net::prelude::*;
use dvm_net::tonic;

use crate::{Clear, DataSource};
use crate::{RemoveModule, DataSource};

/// Receiver for a channel that handles shutdown signals.
pub type ShutdownSig = tokio::sync::oneshot::Receiver<()>;
@@ -178,6 +178,6 @@ impl RemoteCache for GrpcDataSource {
}
}

impl Clear for GrpcDataSource {}
impl RemoveModule for GrpcDataSource {}

impl DataSource for GrpcDataSource {}
@@ -31,14 +31,12 @@ pub use grpc::GrpcDataSource;
pub use blacklist::{BlackListDataSource};

/// Thread-safe `StateView`.
pub trait DataSource: RemoteCache + Clear + Clone + Send + Sync + 'static {}

/// Trait to `clear()` internal data structure.
pub trait Clear {
/// No-op in default implementation.
/// Called on internal `DataSource` object to remove all entries from internal cache.
/// Used when `sender` is the built-in 0x0 / 0x1 address.
fn clear(&self) {
pub trait DataSource: RemoteCache + RemoveModule + Clone + Send + Sync + 'static {}

/// Trait to `remove_module` internal data structure.
pub trait RemoveModule {
/// Removes the module by its id.
fn remove_module(&self, _module_id: &ModuleId) {
//no-op
}
}
@@ -2,7 +2,7 @@ use dvm_info::metrics::execution::ExecutionResult;
use dvm_info::metrics::meter::ScopeMeter;
use libra::prelude::*;

use crate::{Clear, DataSource};
use crate::{RemoveModule, DataSource};

/// Wrapper for data source which collects metrics queries.
#[derive(Debug, Clone)]
@@ -23,12 +23,12 @@ where
}
}

impl<D> Clear for DsMeter<D>
impl<D> RemoveModule for DsMeter<D>
where
D: DataSource,
{
fn clear(&self) {
self.inner.clear();
fn remove_module(&self, module_id: &ModuleId) {
self.inner.remove_module(module_id)
}
}

@@ -5,7 +5,7 @@ use anyhow::Error;

use libra::prelude::*;

use crate::{Clear, DataSource};
use crate::{RemoveModule, DataSource};

/// `StateView` implementation to be used in test_kit.
#[derive(Debug, Clone, Default)]
@@ -115,6 +115,6 @@ impl RemoteCache for MockDataSource {
}
}

impl Clear for MockDataSource {}
impl RemoveModule for MockDataSource {}

impl DataSource for MockDataSource {}

0 comments on commit 334e345

Please sign in to comment.