RFR (M): 8144748: Move assembler/macroAssembler inline function definitions to corresponding inline.hpp files
Volker Simonis
volker.simonis at gmail.com
Mon Dec 7 10:38:42 UTC 2015
On Mon, Dec 7, 2015 at 11:06 AM, Andrew Haley <aph at redhat.com> wrote:
> On 04/12/15 20:23, Mikael Vidstedt wrote:
>> In general, inline functions (apart from trivial ones) should be defined
>> in the inline.hpp file and any .cpp file actually making use of them
>> should include the inline.hpp file instead.
>
> Why does this rule exist? I never did see any reason for it, and I've
> never seen it in any other project. I guess it can break circular
> header dependency problems in some cases, but that's no reason it
> should be a general rule.
>
Breaking dependencies is exactly the reason. The implementations of
inline methods usually have a lot more dependencies compared to the
plain class definition. So if you only need the class definition (e.g.
because you need to declare a field of corresponding type in another
class in another .hpp file) you just have to include the .hpp file. If
you call methods of the corresponding class (usually in .cpp files)
you include the .inline.hpp file.
Unfortunately, as with templates, C++ has no standard mechanism for
finding definitions of inline (or template) functions. They just have
to be available during the compilation of a compilation unit. So the
only alternative to the current schema would be to put all the inline
function definitions into the .hpp files. But this would be ugly and
as you correctly mentioned it would introduce a lot of unnecessary
circular dependencies.
Following the current rules correctly may seem unnecessarily
inconvenient, but I think it is the best we can do. Notice that the
widespread use of precompiled headers often hides problems which are
introduced by not following these rules (because the definition of a
required inline function is present in the PCH database although it is
not explicitly included into a compilation unit). That's why I, as
somebody who has to work with some of the compilers which don't
support precompiled headers, often request a test make without
precompiled headers in JPRT.
Regards,
Volker
> Just curious,
>
> Andrew.
More information about the hotspot-compiler-dev
mailing list