0

I'm trying to copy all the object in the old heap to the new heap as below.

HeapWord* mark = _space->bottom();
    HeapWord* nmark = _nspace->bottom();
    HeapWord* cond = _space->top();
    while(mark < cond){
            oop old_obj = oop(mark);
            if(oop(mark)->getUsed() == 1){
                memcpy(nmark,mark,oop(mark)->size());
                oop new_obj = oop(nmark);
                nmark += new_obj->size();
                _nspace->set_top(nmark);
            }
        mark += oop(mark)->size();
    }

And the structure oop is as below.

typedef class oopDesc* oop;


class oopDesc {
  int used;
  volatile markOop _mark;
  union _metadata {
    Klass*      _klass;
    narrowKlass _compressed_klass;
  } _metadata;
....
//Rest of the functions
....
}

After copying, the contents of the old_obj and new_obj are as below.

enter image description here

How to copy the whole contents of the structure including the contents of the union?.

srccode
  • 721
  • 4
  • 16
  • 1
    Please complete the `oopDesc` code, it has unmatched braces right now. I'm pretty sure what you mean but it's still confusing. Also, this code looks extremely sketchy from a standard C++ perspective (`volatile`, `union`, `memcpy` etc.). The most likely cause for your problem is not following the rule of three/five/zero. – Max Langhof Oct 22 '19 at 13:18
  • ... and use the same name for both (`oop` <-> `oopDesc`???); actually, you should provide a [mre]. – Aconcagua Oct 22 '19 at 13:20
  • Updated the question..please check. – srccode Oct 22 '19 at 13:22
  • Oh, and please don't typedef pointers. That's just information hiding without any further benefit... – Aconcagua Oct 22 '19 at 13:22
  • Actually its the java source code (OpenJDK). I'm trying to modify somethings. – srccode Oct 22 '19 at 13:26
  • About [mre]: In very short words, others should be able just to copy/paste the code into their own IDE, compile and run it and see the error you suffer from. Ask yourself: Would the bit of code you provided even compile? – Aconcagua Oct 22 '19 at 13:28
  • `oop(mark)->size()` cannot compile with the code you gave. There is no `size` method in `oopDesc`. Please make sure that your code has no unrelated errors (or is missing crucial information) so that we can help you with your real problem. You're probably not copying enough bytes, but we have no way to tell because that information is completely missing here. – Max Langhof Oct 22 '19 at 13:29
  • The problem here is not the size() function. After memcpy, it is supposed to have same contents in old_obj and new_obj. Why is that not happening? – srccode Oct 22 '19 at 13:31
  • At very least: Have you tried [debugging](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) the code? Step into memcpy and check the parameters provided, are the pointers correct, is size correct, .... For analysing: It can be pretty helpful to compare old and new code with a diff tool to see what you actually changed. Ask yourself why the previous code *did* work and how the changes might have led to new code failing. – Aconcagua Oct 22 '19 at 13:55

0 Answers0