Whenever a class is derived virtually, it adds a virtual pointer (vptr pointing to the vtable) to the class. Hence the size of Derived2 is equal to the size of pointer.
For Derived4, both vptr and padding come into picture.
To understand this better, try to add another int variable or int pointer to Dummy class, and check its size.
Since Derived4 is virtually derived, a pointer is added. Since a pointer variable and a char variable are present in the class, compiler will do padding and hence the size would be 8.