Git Product home page Git Product logo

virtualfunctionperf's People

Contributors

cleak avatar emilrezanina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

virtualfunctionperf's Issues

vc call function not directly, they all via jmp table

when you see in the disassembly, you would find vc calls jump to the jmp tables why the calls can be hooked.
a virtual method call in the vc disassemby code, it first jump to the jmp table and then access the virtual table.
a non-virtual method call at first jump to the jmp table and then jmp to actual text code.
when call the a virtual method directly like you do, the disassembly code skip the first jump and directly access the virtual table pointer. thus you think it beats the non-virtual method calls.

and gcc implements virtual table pointer very different from vc, it may generate branches. calling virtual method like you supposed may beats nonvirt method more much. but that is not the fact.

It looks main.c is not gcc friendly.

Looking at system call there is a PAUSE command invoke so I was afraid this was not going to compile with gcc.
Fixing is ease: gcc supports attribute((noinline)) void IncrementDirect() instead of declspec

Issue with vtable trick was not that easy to fix:

(gdb) p *((void **) obj)
$26 = (void *) 0x403070 <vtable for IncrementerVirtual+16>

Using your syntax:

(gdb) p ((((void ***) obj))+0)
$161 = (void *) 0x401c60 IncrementerVirtual::~IncrementerVirtual()
(gdb) p ((((void ***) obj))+1)
$162 = (void *) 0x401c88 IncrementerVirtual::~IncrementerVirtual()
(gdb) p ((((void ***) obj))+2)
$163 = (void *) 0x401cb4 IncrementerVirtual::Increment()

In your code offset +1 points to destructor, so I had to use offset +2 in your code.

With my syntax using array index:
VoidMemberFn* updateFn = (VoidMemberFn*)(&(GetVTable(dynamic_cast<IncrementerBase*> (objs[0])))[2]);

Very nice program by the way

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.