History log of /art/runtime/class_loader_context.cc
Revision Date Author Comments
0d6736f8355be80ceb6ab853f8fdad45028f071f 16-Apr-2018 Mathieu Chartier <mathieuc@google.com> Add arg for overwriting class loader class path

Added stored_context srgument to EncodeContextForOatFile that
overwrites the class path when non-null.

This is used by the --stored-class-loader-context argument. Fixed
the test.

Bug: 70934104
Bug: 67345922
Test: test-art-host-gtest

(cherry picked from commit c4440775c5627fed9701e14a1f9d14dca27ed176)

Merged-In: If877d8cfe9d34eeaa941e9f6df2e12539d9c4a6f
Change-Id: I16fde69bad07ae173fa30dff2fcda50b000779a5
8548de1c9f403b917eb2ad74a9922127da61171d 24-Mar-2018 Mathieu Chartier <mathieuc@google.com> Add stored class loader context option

Motivation: Enable having a different class loader context during
preopt vs the one stored in the oat file.

Added test.

Bug: 70934104
Bug: 67345922

Test: test-art-host

(cherry picked from commit f5abfc42f0d986b9f8eb782d7e761f1a08784210)

Merged-In: I6c0851370e0740e5f47faf25a5494022034f6fa4
Change-Id: I6c0851370e0740e5f47faf25a5494022034f6fa4
013fd8073f3ece22b0bba1853d3f3430c8a9e4bd 12-Jan-2018 David Sehr <sehr@google.com> Create an ART-independent DexFileLoader

Opening DEX files should not rely on instantiating a runtime or having a
large number of dependencies on runtime components. This CL makes
DexFileLoader a stub class that is independent of ART, and introduces a
subclass ArtDexFileLoader that contains the current implementations.

Bug: 22322814
Test: make -j 50 test-art-host
Change-Id: Ia6e92ae93c347057ea0c10455525239cbbe42c03
9e734c7ab4599d7747a05db0dc73c7b668cb6683 05-Jan-2018 David Sehr <sehr@google.com> Create dex subdirectory

Move all the DexFile related source to a common subdirectory dex/ of
runtime.

Bug: 71361973
Test: make -j 50 test-art-host
Change-Id: I59e984ed660b93e0776556308be3d653722f5223
06ffecfe4260d64850df23023ed94b167438d996 14-Nov-2017 Nicolas Geoffray <ngeoffray@google.com> Don't add a '/' if it's already there.

Test: class_loader_context_test
Change-Id: I3fd310cf9c2da6c295ba479d0f8f4ba3137feda1
92003fe2d5f9031f56c8b0407d8d934023fb4cb2 06-Sep-2017 Calin Juravle <calin@google.com> Revert "Use real locations when opening dex files from the context"

This reverts commit 821a2595e2438554424879d6cb3594810ca8e636.

Reason for revert: Oat file assistant logic was updated to not
use realpaths anymore. So this is no longer needed.

Test: m test-art-host-gtest

Change-Id: Ia63a50f60b82ec3e20606d0be852607c9d2eb26e
e875f4c210ce0598e47b6d66ec12cd7c60208844 26-Oct-2017 Nicolas Geoffray <ngeoffray@google.com> Don't verify dex file when the runtime is in NoVerify mode.

bug: 30972906
bug: 63920015

Test: systrace of priv-app with OOB, no verification at startup
Change-Id: I479a7ddcfa495228a379744b23c26fa8c91c3dde
095c6c96236476b605b3ac672f6d2b8c151e9479 19-Oct-2017 Nicolas Geoffray <ngeoffray@google.com> Pass the verify flag to DexFileLoader utilities.

Refactoring-only change.

Also remove unused DexFilerLoader::OpenMemory.

bug: 30972906
bug: 63920015

Test: build.

Change-Id: I7cd4b5787565ab1a3457ce2be6bb14657229c550
79c87da9d4698ec58ece65af0065eebd55a1cfe0 10-Oct-2017 Mathieu Chartier <mathieuc@google.com> Add DexFileLoader class

Added DexFileLoader class, moved functionality from DexFile there:
- Multidex loading logic
- DexFile opening logic for Zip and etc
- Some other helpers

Bug: 63756964
Test: test-art-host

Change-Id: Ic3dfa458947d4b69912dea5cdd836e7e8f55061c
91842aebfa418f5efad8933a9d79db097f079246 07-Sep-2017 Alex Light <allight@google.com> Lower PLOG(ERROR) to PLOG(WARNING) if unable to find realpath

We were emitting a PLOG(ERROR) from class_loader_context if we are
unable to find the dex-files realpath. This is an issue because
InMemoryDexClassLoader and some --redefine-stress tests cause this
message to be printed, making the test fail.

This also brings it more into line with other logs in this file.

Test: ./test/run-test --host --jvmti-redefine-stress 071
Change-Id: Idc21bf89be02ca9263fbec7f28fdf036196ab58c
c5b215f7004c46a274a54e232f0cd146c7494f9a 12-Sep-2017 Calin Juravle <calin@google.com> Update the context classpath after the dex files are opened.

The classpath stored in the context maybe be out of sync with the list of
opened dex files if any of the dex file is a multidex or cannot be opened.

This CL ensures that OpenDexFiles updates the classpath with the dex file
locations that were open.

The change does not affect the current use of ClassLoaderContext. It is a
preparatory step for b/62269291

Bug: 62269291
Test: m test-art-host-gtest-class_loader_context_test
Change-Id: Ibe675df9b2c06a4df8189f0d72df8b4061603a0e
e3a51549a3b458fb9d8dee5a267889a4e70c26b2 12-Sep-2017 Calin Juravle <calin@google.com> Update the context classpath after the dex files are opened.

The classpath stored in the context maybe be out of sync with the list of
opened dex files if any of the dex file is a multidex or cannot be opened.

This CL ensures that OpenDexFiles updates the classpath with the dex file
locations that were open.

The change does not affect the current use of ClassLoaderContext. It is a
preparatory step for b/62269291

Bug: 62269291
Test: m test-art-host-gtest-class_loader_context_test
Change-Id: Ibe675df9b2c06a4df8189f0d72df8b4061603a0e
cf24cee8938c72bfc755fcb7e0376b5e5e0fcf56 06-Sep-2017 Calin Juravle <calin@google.com> Fix context verification for relative dependencies

If --classpath-dir is passed, dex2oat encodes the dependencies as relative
paths in the class loader context.

However, at runtime we always get the full apk paths. This means we will
always get a context mismatch because even if we have the same file we
encode its path differently at runtime and compile time.

Only the split apks are affected by this issue since they will depend on
the base apk which will be encoded as a relative location.

The fix is to propagate the behavior from OatFile::Setup() which resolves
the relative locations.

In fixing this I took a bit more general approach and try to infer the
context locations that should be compared based on the actual context and
the expected context.

Bug: 65385993
Test: m test-art-host-gtest
manual with split-apks

(cherry picked from commit 1e96a5d58d68909cbc2d6bf2ee08c6c11f7b858e)

Merged-In: I414ec05da5ab4716f513d9bdb1e1b9384eeb38fa
Change-Id: Ibd36a0ed23f2a76ad6e109801fbb9e78910dbe64
1e96a5d58d68909cbc2d6bf2ee08c6c11f7b858e 06-Sep-2017 Calin Juravle <calin@google.com> Fix context verification for relative dependencies

If --classpath-dir is passed, dex2oat encodes the dependencies as relative
paths in the class loader context.

However, at runtime we always get the full apk paths. This means we will
always get a context mismatch because even if we have the same file we
encode its path differently at runtime and compile time.

Only the split apks are affected by this issue since they will depend on
the base apk which will be encoded as a relative location.

The fix is to propagate the behavior from OatFile::Setup() which resolves
the relative locations.

In fixing this I took a bit more general approach and try to infer the
context locations that should be compared based on the actual context and
the expected context.

Bug: 65385993
Test: m test-art-host-gtest
manual with split-apks

Change-Id: I4c8e7c4f0a3a18dba8daca752a21da4822cce490
07828ba55e3e7a8ba8337e502755e2ab68893d92 11-Aug-2017 Calin Juravle <calin@google.com> Use real locations when opening dex files from the context

The oat file assistant uses real locations when opening dex files which
will later be checked against the class loader context embedded in the oat
file. In order to guarantee a match we need to use real paths in the
context as well.

Bug: 64460009
Test: m test-art-host-gtest
Merged-In: Ic341285a792ac60895a8dbde319fd5d1d032498f

(cherry picked from commit 821a2595e2438554424879d6cb3594810ca8e636)

Change-Id: I9da4f977dd456d26ecd464b563c0ece25eab77f6
7252738e5c8aa439e2c98e4b887c5eab20cd38c5 03-Sep-2017 Andreas Gampe <agampe@google.com> ART: Don't prepend '/' if classpath_dir is empty

When no classpath_dir is given, do not prepend '/' to a relative
dex location.

Add tests.

Bug: 65318303
Test: m test-art-host-gtest-class_loader_context_test
Test: m test-art-host
Change-Id: Ib374815ce3fa9d67694f3a23037cd3b8eea35173
821a2595e2438554424879d6cb3594810ca8e636 11-Aug-2017 Calin Juravle <calin@google.com> Use real locations when opening dex files from the context

The oat file assistant uses real locations when opening dex files which
will later be checked against the class loader context embedded in the oat
file. In order to guarantee a match we need to use real paths in the
context as well.

Bug: 64460009
Test: m test-art-host-gtest
Change-Id: I1b564baa0c933172891a10a448ce1ef129be5ea2
c6d79e6cd8093075809971e303b7ce2def1a1cf3 03-Aug-2017 Calin Juravle <calin@google.com> Stop using the runtime classpath in dex2oat

Use only --class-loader-context to infer the classpath that should be used
for compilation.

The tests and benchmarks no longer rely on --runtime-arg --classpath being
passed to dex2oat.

Bug: 38138251
Test: m test-art-host

(cherry picked from commit 84f82b9972ec29bd05b1575ae6d638255be2f285)

Change-Id: I980f850ab0524812d18c3af34073cae25484837a
e6b4298bc8934adee599057ae65b673c30119ee1 26-Jul-2017 Calin Juravle <calin@google.com> Pass the class loader context to dex2oat when optimizing at runtime

Until now we always passed the special shared library symbol "&" when we
called dex2oat at runtime without an explicit class path.

This CL changes that and passes the class loader context inferred from the
runtime class loaders to dex2oat. If any of the runtime class loaders is
not supported we continue to pass the special library symbol.

Bug: 38138251
Test: m test-art-host

(cherry picked from commit 27e0d1f3da2e0b7046dacb40794739d739e454a3)

Change-Id: I054d12c9e2c923d7abfae1a968a2849e31af164e
1991589d4515561411156473c89d77d295183bdd 03-Aug-2017 Calin Juravle <calin@google.com> Revert "Revert "Stop using the runtime classpath in dex2oat""

This reverts commit 053a84b762536144d5cae309ca5abd97766b4583.

Reason for revert: Prepare the CL again to be submitted after
https://chrome-internal-review.googlesource.com/c/423809 gets merged.

Change-Id: I1d0e3d6bf2aa16249b2d0146acd9c81149924c00
053a84b762536144d5cae309ca5abd97766b4583 03-Aug-2017 Calin Juravle <calin@google.com> Revert "Stop using the runtime classpath in dex2oat"

This reverts commit 84f82b9972ec29bd05b1575ae6d638255be2f285.

Reason for revert: I submitted this to ealrly. It needs to be submitted after https://android-review.googlesource.com/c/450390 gets merged

Change-Id: I91e6259b61d72a48a1d18e62f53ef82f18692930
84f82b9972ec29bd05b1575ae6d638255be2f285 03-Aug-2017 Calin Juravle <calin@google.com> Stop using the runtime classpath in dex2oat

Use only --class-loader-context to infer the classpath that should be used
for compilation.

The tests and benchmarks no longer rely on --runtime-arg --classpath being
passed to dex2oat.

Bug: 36044779
Test: m test-art-host
Change-Id: Iba4cb3489f4a1a4a421071e1889d806d6c1d0738
27e0d1f3da2e0b7046dacb40794739d739e454a3 26-Jul-2017 Calin Juravle <calin@google.com> Pass the class loader context to dex2oat when optimizing at runtime

Until now we always passed the special shared library symbol "&" when we
called dex2oat at runtime without an explicit class path.

This CL changes that and passes the class loader context inferred from the
runtime class loaders to dex2oat. If any of the runtime class loaders is
not supported we continue to pass the special library symbol.

Bug: 38138251
Test: m test-art-host
Change-Id: Ica43ee8a3f36dab2d9ed0e634a9f6341379c8e1c
f7e5ff28afa09c3c5934b9397b89079ef6ea1f63 26-Jul-2017 Andreas Gampe <agampe@google.com> ART: Add more logging to ClassLoaderContext mismatches

To aid in debugging, add the original specifications to the warning.

Bug: 63977059
Test: m test-art-host

(cherry picked from commit 7d0f81c51518d7f7756ccc49ff4b5d6a829eef8e)

Change-Id: Ie2a2cdf41924733d45f79a42d6c9f2a4cb94ec4f
fdc3c3dd0daaed56d24ee648d123a0156c0bca8a 25-Jul-2017 Calin Juravle <calin@google.com> Be prepared to handle empty class loader contexts

When executing run-tests we can hit an empty class loader contexts if the
compilation sources are passed with "-cp" and later removed from the
context.

Be prepared for such case and assume a PathClassLoader context.

Bug: 63977059
Test: ./art/test/run-test --host --optimizing --dev
test-art-host

(cherry picked from commit 1a509c8effc938ba3da0f90ad83abb124b296386)

Change-Id: I2db637a1fc83beb760e1724edd6138b0614aa19b
7d0f81c51518d7f7756ccc49ff4b5d6a829eef8e 26-Jul-2017 Andreas Gampe <agampe@google.com> ART: Add more logging to ClassLoaderContext mismatches

To aid in debugging, add the original specifications to the warning.

Bug: 63977059
Test: m test-art-host
Change-Id: Icbf7da9cbce1641b99d8572e09d74141c71e9fe9
1a509c8effc938ba3da0f90ad83abb124b296386 25-Jul-2017 Calin Juravle <calin@google.com> Be prepared to handle empty class loader contexts

When executing run-tests we can hit an empty class loader contexts if the
compilation sources are passed with "-cp" and later removed from the
context.

Be prepared for such case and assume a PathClassLoader context.

Bug: 63977059
Test: ./art/test/run-test --host --optimizing --dev
test-art-host

Change-Id: Id0fa853b2407e358592f89766adb5dad19137289
41acdc1df1bceaa462d134b8ce30419d301e76d7 19-Jul-2017 Calin Juravle <calin@google.com> Fix the default ownership of dex files in ClassLoaderContext

By default the context should have the ownership.

Test: valgrind --leak-check=full
../out/host/linux-x86/nativetest/art_runtime_tests/class_loader_context_test
Bug: 38138251

Change-Id: I21ff048018abba61999b6025281c73fc9899cae0
c79470dd970dd30cf3b383c635543e8af3761478 13-Jul-2017 Calin Juravle <calin@google.com> Allow dex2oat to create a full class loader context

We previously checked that dex2oat sees only a single class loader. This
CL removes the restriction and enables dex2oat to create and compile with
a full class loader context.

Test: m test-art-host
Bug: 38138251
Change-Id: I03e75a75757995ce8ce3addf0bc0a708e18ac050
3f9186446faa01636475596335240f39472ba9f4 12-Jul-2017 Calin Juravle <calin@google.com> Verify the class loader context when loading oat files

Previously, the oat_file_manager would expect and perform validation on a
simple classpath: a list of dex files separated by ':'.

This is no longer enough since the oat file may encode a chain of class
loaders now. The CL moves the validation logic in ClassLoaderContext and
extends it to verify the complete chain of class loaders.

Test: m test-art-host
Bug: 38138251
Change-Id: I8ac9c65db1a14909aaecb04fa7a7115ddedc673f
57d0accc081c1779edb604ab86e5a4c0cfba16eb 12-Jul-2017 Calin Juravle <calin@google.com> Create a class loader context starting from an existing ClassLoader

Extend ClassLoaderContext to be able to generate a context from an
existing class loader.

This will be used in extending the duplicate class check to cover
DelegateLastClassLoaders.

Most of the functionality is migrated from OatFileManager with some
cleanups consisting of extra docs and more conservative checks on the
integrity of the class loader chain.

Test: m test-art-host
Bug: 38138251
Change-Id: If7c18cb75bfc9e6784676f96a666bf13b04c8b8b
7b0648aa7cb4b7a58e73bf353e031dfe4553d9d7 08-Jul-2017 Calin Juravle <calin@google.com> Move dex files dependencies (en/de)coding to ClassLoaderContext

Encode the full class loader context in the oat file (rather than just a
list of dex files).

The context encoding matches the format used by dex2oat with the addition
of checksums.

Temporarily assert that at decoding time we are operating on a
PathClassLoader until the checking logic covers all supported cases.

Also, bump the version of the oat file because the format of the classpath
key has changed.

This is a transition step to minimize the size of follow up changes.

Test: m test-art-host
Bug: 38138251
Change-Id: I9ec0cfe092ce1afccb741a36e737896880d5f1d2
87e2cb64ab02d9bdc48255130c67168c809c5f62 14-Jun-2017 Calin Juravle <calin@google.com> Add support for processing class loader contexts

Initial support for recognizing the class loader contexts.

In order to correctly compile dex files which at runtime are loaded with
a non-trivial class loader chain we need to make dex2oat aware of the
precise runtime context.

This CL adds the infrastructure to process arbitrary and arbitrary chain
of class loaders. ClassLoaderContext is able to parse a class loader
spec from a string and create the runtime structure based on it.

The integration with dex2oat and oat file assistant will follow up.

The string specification looks like
"PCL[lib1.dex:lib2.dex];DLC[lib3.dex]"

It describes how the class loader chain should be build in order to
ensure classes are resolved during dex2aot as they would be resolved at
runtime. This spec will be encoded in the oat file. If at runtime the
dex file will be loaded in a different context, the oat file will be
rejected.

The chain is interpreted in the natural 'parent order', meaning that
class loader 'i+1' will be the parent of class loader 'i'. The
compilation sources will be added to the classpath of the last class
loader. This allows the compiled dex files to be loaded at runtime in a
class loader that contains other dex files as well (e.g. shared
libraries).

Note that we accept chains for which the source dex files specified
with --dex-file are found in the classpath. In this case the source dex
files will be removed from the any class loader's classpath possibly
resulting in empty class loaders.

* This is the first CL, which adds the infrastructure for processing
a class loader context. Currently it CHECKS that only a single
PathClassLoader is created.

Test: m test-art-host
Bug: 38138251
Change-Id: I312aa12b5732288f3c1df4746b5775a32e0bfb04