RFR: 8311661: Resolve duplicate symbol of StringTable::StringTable with JDK static linking [v2]

Ioi Lam iklam at openjdk.org
Tue Jul 11 17:05:56 UTC 2023


On Tue, 11 Jul 2023 16:39:50 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Jiangli Zhou has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
>> 
>>  - Merge branch 'master' into JDK-8311661
>>  - Move  '} // namespace JavaClassFile' to after '#endif //INCLUDE_CDS_JAVA_HEAP'.
>>  - 8311661: Resolve duplicate symbol of StringTable::StringTable with JDK static linking
>
> `using namespace hotspot;` could be used I think:
> 
>> using namespace ns-name ; | (5)
> 
>> 5) [using-directive](https://en.cppreference.com/w/cpp/language/namespace#Using-directives): From the point of view of unqualified [name lookup](https://en.cppreference.com/w/cpp/language/lookup) of any name after a using-directive and until the end of the scope in which it appears, every name from ns-name is visible as if it were declared in the nearest enclosing namespace which contains both the using-directive and ns-name.
> 
> (From: https://en.cppreference.com/w/cpp/language/namespace)
> 
> But, if we put everything in the same `hotspot` namespace we shouldn't need to add `hotspot::` qualifiers since things in the same namespace can already refer to each other:
> 
> 
> namespace hotspot {
> class Bar {
> public:
>   static int a() { return 0; }
> };
> 
> int func(Bar* bar) { // Bar is unqualified here
>   return bar->a();
> }
> }

> Global namespace (as @JornVernee has suggested) does sound attractive as long as we can do it without very invasive changes. It's also a more future-proof solution. I'll do some exploration as well.

Something like this might work. We need to enclose all declarations inside `namespace hotspot {...}`, so all .hpp files need to be touched (which I think is OK).

We can add the `using namespace hotspot` in precompiled.hpp so we that can avoid modifying most .cpp files.

`using namespace` affects only the lookup of existing names. It doesn't affect the declaration of new types (like Bar in my example below).


// precompiled.hpp
namespace hotspot {}
using namespace hotspot;

// foo.hpp
namespace hotspot {
  class Foo {
    public:
    static int x();
  };
}


// bar.hpp
class Bar { // declares ::Bar, not hotspot::Bar
public:
  static int a() { return 2; }
};


// foo.cpp
int Foo::x() { return 1; } // defines Hotspot::Foo::x()

int main() {
  printf("%d %d\n", Foo::x(), hotspot::Foo::x());
  //printf("%d %d\n", Bar::a(), hotspot::Bar::x()); <-- this doesn't work
}

-------------

PR Comment: https://git.openjdk.org/jdk/pull/14808#issuecomment-1631178570


More information about the graal-dev mailing list