of 40

• date post

30-Dec-2015
• Category

## Documents

• view

43

0

Embed Size (px)

description

Region-based Memory Management in Cyclone について. 発表者 : 前田俊行. Cyclone とは ?. 安全な C の方言 型による静的安全性チェック 配列境界検査などの動的安全性チェック それでいてプログラマに低レベルなメモリ制御をさせたい. Cyclone プログラムの例. ほとんど C と変わらない 書換率 = 10% 以下 ( 著者らの経験による ). void factorial(int* result, int n) { int x = 1; if (n > 1) { - PowerPoint PPT Presentation

### Transcript of Region-based Memory Management in Cyclone «¤„¦

• Region-based Memory Managementin Cyclone :

• Cyclone?C

• CycloneC = 10% ()void factorial(int* result, int n){int x = 1;

if (n > 1) {factorial(&x, n 1);}*result = x * n;}

• Cycloneregionvoid factorial(int* result, int n){int x = 1;

if (n > 1) {factorial(&x, n 1);}*result = x * n;}

• Region?RegionRegionLIFO

• LIFOregionRegion =pushRegion =pop

• Region : 2regionregionregionregion

• CycloneRegionregion (region)region (region)regionregion (region)

• Region (region)regionint sys_mlock(int start, int length){}regionint startint lengthRegionregion

• Region (region)regionint sys_mlock(int start, int length){}Regionregion

• Region(region)region{int i;struct stat s;

}Regionregionint istruct stat s

• RegionregionregionRegionregionint istruct stat sregion x {int i;struct stat s;

}

• Regionrnewregion x {int? array =rnew(x) { for i < n : i };}RegionregionInt? arrayRegion

• region (region)regionregionmalloc regionint global_counter;void func(){malloc();}int global_counterregion

• Cyclone int* function(){int x;

return &x;}

• Cycloneregion() int*region region

• 1int* p; {int x = 0;

p = &x;}*p = 123;p

• 2int* p; {int x = 0;

p = &x;}*p = 123;p&xp : int*&x : int*

• Regionregionchar?1 strcpy (char?1, const char?2);char?H strdup (const char?);char?1 rstrdup (region_t, const char?2); : Cyclone()H region

• Regionstrdupchar?1 rstrdup (region_t, const char?2);

char?H strdup (const char? str){return rstrdup (heap_regions, str);}

()H, heap_regions region

• Regionregionstruct List {int*1 head;struct List *2 tail;}; :

• Subtypingregionvoid f (int b, int*1 p1, int*2 p2)3 {int*3 p;if (b)p = p1;elsep = p2;}123

• region 1: 2: regionregion3: region

• list_t list_copy(list_t lst){list_t res = NULL;

for (list_t t = lst; t != NULL; t = t->tail)res = new List(new *t->hd, res);return res;}list_t list_copy (list_t lst){list_t res = NULL;

for (list_t t = lst; t != NULL; t = t->tail)res = new List(new *t->hd, res);return res;}struct List {int*1 head;struct List *2 tail;};typedef struct List *2 list_t ;

• ExistentialExistentialCycloneexistential

• Existentialstruct IntFn {int (*func)(); env;}Existentialstruct IntFn_int {int (*func)(int*);int* env;}struct IntFn_List {int (*func)(struct List*);struct List* env;}existential(pack)PackPack

• Existentialpackstruct IntFn {int (*func)(); env;}int read (int* x) { return *x; }

L {int x = 0;struct IntFn pkg ={ .func = read , .env = &x };}Existentialpackint*L

• Existentialunpackstruct IntFn {int (*func)(); env;}int read (int* x) { return *x; }

int apply_IntFn(struct IntFn pkg){let IntFn { .func = f, .env = x } = pkg;return f ( x );}Existentialunpack f : int (*)() x :

• ExistentialExistentialdangling

• Existentialdanglingstruct IntFn {int (*func)(); env;}int read (int* x) { return *x; }L1 {struct IntFn pkg;L2 {int x = 0;pkg ={ .func = read , .env = &x };}}Dangling

• 1effectEffect = ()regionregion effectEffectregion

• effect?regioneffectconservative : effect

• effectint*1 f ( int*2, int*1*3);Effect : {1, 2, 3}int compare(, );Effect : { regions_of () }regions_of: regions_of (int) = 0 () regions_of (*) = { } regions_of () regions_of ((1, , n) ) = regions_of (1) regions_of (2) regions_of ()

• 2RegionRegion = regionregionExistentialregionExistentialpackregionExistentialunpackregion

• Regionexistentialstruct IntFn : regions_of ()
• Regionexistential packstruct IntFn : regions_of ()
• Regionexistential packstruct IntFn : regions_of ()
• ExistentialunpackL {struct IntFn pkg;let IntFn { .func = f, .env = x } = pkg;

f ( x );}struct IntFn : regions_of ()

• Cycloneregion-basedCExistentialeffectregion

• ReferencesCyclone homepage http://www.cs.cornell.edu/projects/cycloneRegion-based Memory Management in Cyclone, Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. PLDI2002. To appear.