本文介绍了GC Roots的误解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Roots是:


  • 静态字段

  • 方法参数

  • 本地fielfs

  • f-队列,其中还包含指向将要完成的对象的指针

  • cpu寄存器< = ???




现在我们来讨论一下寄存器。



这些代码可以包含就像:

  mov bx,0034h; bx = 52(存储在16位中)
mov cl,bl; cl = bx的低8位
mov eax,ecx
call print_int

但是 wait



如果我没有弄错,这是持有这些< static 本地参数 - 从第一位! p>

那么为什么要写这个 TWICE ? (或从另一个方向?)



为什么写(例如)

  Foo f = new Foo(); 

**还有**

mov bx,0034h //< --------代表`f`地址或类似的那个



编辑



我的关于寄存器的问题来自这里:

解决方案

考虑

  string sentence = ... 
int wordCount = sentence.Split('') 。长度;

String.Split()产生一个数组,它必须保持可达。但是没有指向它的变量或参数,优化器很可能会将引用保存在寄存器中。

所以CPU(地址)寄存器必须被认为是根的一部分。

I know that Roots are :

  • static fields
  • method parameters
  • local fielfs
  • f-queue which also holds a pointer to the " going to be finilized" objects
  • cpu registers <=???

Now lets talk about registers.

the code whch they can contain is like :

mov bx, 0034h   ; bx = 52 (stored in 16 bits)
mov cl, bl      ; cl = lower 8-bits of bx
mov eax, ecx
call print_int

but wait !

If im not mistaken , this is the actually code which was Holding those those static , local and parameters - from the first place !

So why to write this TWICE ? ( or from another direction ?)

Why to write ( for example )

  Foo f = new Foo();

**and also** 

mov bx, 0034h   //<-------- represents the `f` address or something like that 

edit

my question about registers comes from here :

解决方案

Consider

string sentence = ...
int wordCount = sentence.Split(' ').Length;

String.Split() produces an array, it must be kept reachable for (part of ) this statement. But there is no variable or parameter pointing to it, the optimizer will most likely keep the reference in a register.

So CPU (address) registers must be considered part of the roots.

这篇关于GC Roots的误解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 04:47